Prechádzať zdrojové kódy

cmAlgorithms: Maintain the pivot iterator in cmRemoveIndices.

Avoid the algorithm of 'Schlemiel the painter' in the case of
iterators which are not RandomAccess.
Stephen Kelly 10 rokov pred
rodič
commit
7fd8557f4c
1 zmenil súbory, kde vykonal 4 pridanie a 2 odobranie
  1. 4 2
      Source/cmAlgorithms.h

+ 4 - 2
Source/cmAlgorithms.h

@@ -239,12 +239,14 @@ typename Range::const_iterator cmRemoveIndices(Range& r, InputRange const& rem)
 
   typename Range::iterator writer = r.begin();
   std::advance(writer, *remIt);
+  typename Range::iterator pivot = writer;
+  typename InputRange::value_type prevRem = *remIt;
   ++remIt;
   size_t count = 1;
   for ( ; writer != r.end() && remIt != rem.end(); ++count, ++remIt)
     {
-    typename Range::iterator pivot = r.begin();
-    std::advance(pivot, *remIt);
+    std::advance(pivot, *remIt - prevRem);
+    prevRem = *remIt;
     writer = ContainerAlgorithms::RemoveN(writer, pivot, count);
     }
   writer = ContainerAlgorithms::RemoveN(writer, r.end(), count);