diff options
author | Stephen Kelly <steveire@gmail.com> | 2015-02-20 21:19:14 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2015-02-24 14:16:02 (GMT) |
commit | 47c2da6aa8c8f77e8d01b68cd5de596da2b2c3d7 (patch) | |
tree | b2c8dbf1af5bb91dc96ad0d9914a49d6015a8fb6 /Source/cmAlgorithms.h | |
parent | a5b10ae68a4a84face73767f96189673015946be (diff) | |
download | CMake-47c2da6aa8c8f77e8d01b68cd5de596da2b2c3d7.zip CMake-47c2da6aa8c8f77e8d01b68cd5de596da2b2c3d7.tar.gz CMake-47c2da6aa8c8f77e8d01b68cd5de596da2b2c3d7.tar.bz2 |
cmAlgorithms: Cache the end iterators in algorithms.
Diffstat (limited to 'Source/cmAlgorithms.h')
-rw-r--r-- | Source/cmAlgorithms.h | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h index 43023db..b9d7e78 100644 --- a/Source/cmAlgorithms.h +++ b/Source/cmAlgorithms.h @@ -236,6 +236,7 @@ template<typename Range, typename InputRange> typename Range::const_iterator cmRemoveIndices(Range& r, InputRange const& rem) { typename InputRange::const_iterator remIt = rem.begin(); + typename InputRange::const_iterator remEnd = rem.end(); typename Range::iterator writer = r.begin(); std::advance(writer, *remIt); @@ -243,13 +244,14 @@ typename Range::const_iterator cmRemoveIndices(Range& r, InputRange const& rem) typename InputRange::value_type prevRem = *remIt; ++remIt; size_t count = 1; - for ( ; writer != r.end() && remIt != rem.end(); ++count, ++remIt) + const typename Range::iterator rangeEnd = r.end(); + for ( ; writer != rangeEnd && remIt != remEnd; ++count, ++remIt) { std::advance(pivot, *remIt - prevRem); prevRem = *remIt; writer = ContainerAlgorithms::RemoveN(writer, pivot, count); } - return ContainerAlgorithms::RemoveN(writer, r.end(), count); + return ContainerAlgorithms::RemoveN(writer, rangeEnd, count); } template<typename Range, typename MatchRange> @@ -267,8 +269,9 @@ typename Range::const_iterator cmRemoveDuplicates(Range& r) unique.reserve(r.size()); std::vector<size_t> indices; size_t count = 0; + const typename Range::iterator end = r.end(); for(typename Range::const_iterator it = r.begin(); - it != r.end(); ++it, ++count) + it != end; ++it, ++count) { const typename UniqueVector::iterator low = std::lower_bound(unique.begin(), unique.end(), *it); @@ -283,7 +286,7 @@ typename Range::const_iterator cmRemoveDuplicates(Range& r) } if (indices.empty()) { - return r.end(); + return end; } return cmRemoveIndices(r, indices); } |