svl/source/items/itemset.cxx |   29 ++++++++++-------------------
 1 file changed, 10 insertions(+), 19 deletions(-)

New commits:
commit 53949256dd1fb0741009cc46e112ba3a00c33b39
Author: Jochen Nitschke <j.nitschke+loger...@ok.de>
Date:   Tue Nov 1 01:08:55 2016 +0100

    simplify loop to O(n)
    
    Change-Id: Ib14da0201730e213f15f4f46b539fc843bfbe750
    Reviewed-on: https://gerrit.libreoffice.org/30454
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/svl/source/items/itemset.cxx b/svl/source/items/itemset.cxx
index 9a67f73..6c00f5c 100644
--- a/svl/source/items/itemset.cxx
+++ b/svl/source/items/itemset.cxx
@@ -625,29 +625,20 @@ void SfxItemSet::MergeRange( sal_uInt16 nFrom, sal_uInt16 
nTo )
     auto needMerge = [](std::pair<sal_uInt16, sal_uInt16> lhs, 
std::pair<sal_uInt16, sal_uInt16> rhs)
                      {return (lhs.first-1) <= rhs.second && (rhs.first-1) <= 
lhs.second;};
 
-    for (;;)
+    std::vector<std::pair<sal_uInt16, sal_uInt16> >::iterator it = 
aRangesTable.begin();
+    std::vector<std::pair<sal_uInt16, sal_uInt16> >::iterator itNext;
+    // we got at least one range
+    while ((itNext = std::next(it)) != aRangesTable.end())
     {
         // check neighbouring ranges, find first range which overlaps or 
adjoins a previous range
-        std::vector<std::pair<sal_uInt16, sal_uInt16> >::iterator it = 
aRangesTable.begin();
-        if (it == aRangesTable.end())
-            break;
-        std::vector<std::pair<sal_uInt16, sal_uInt16> >::iterator itNext;
-        for (;;)
+        if (needMerge(*it, *itNext))
         {
-            itNext = std::next(it);
-            if (itNext == aRangesTable.end())
-                break;
-            if (needMerge(*it, *itNext))
-                break;
-            ++it;
+            // lower bounds are sorted, implies: it->first = min(it[0].first, 
it[1].first)
+            it->second = std::max(it->second, itNext->second);
+            aRangesTable.erase(itNext);
         }
-        if (itNext == aRangesTable.end())
-            break;
-
-        // merge with next range
-        // lower bounds are sorted, implies: it->first = min(it[0].first, 
it[1].first)
-        it->second = std::max(it->second, itNext->second);
-        aRangesTable.erase(itNext);
+        else
+            ++it;
     }
 
     // construct range array
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to