summaryrefslogtreecommitdiff
path: root/svl
diff options
context:
space:
mode:
authorJochen Nitschke <j.nitschke+logerrit@ok.de>2016-11-01 01:08:55 +0100
committerNoel Grandin <noel.grandin@collabora.co.uk>2016-11-01 12:38:35 +0000
commit53949256dd1fb0741009cc46e112ba3a00c33b39 (patch)
treee32cc73143ef723198a329b60836ce2a24c5dc1e /svl
parent39414827352e58e8be76abaa9a5a1ac9518d927f (diff)
simplify loop to O(n)
Change-Id: Ib14da0201730e213f15f4f46b539fc843bfbe750 Reviewed-on: https://gerrit.libreoffice.org/30454 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svl')
-rw-r--r--svl/source/items/itemset.cxx29
1 files changed, 10 insertions, 19 deletions
diff --git a/svl/source/items/itemset.cxx b/svl/source/items/itemset.cxx
index 9a67f73f52d8..6c00f5c009c8 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