]> granicus.if.org Git - clang/commitdiff
Add 'insert()' to BumpVector. Patch by Marcin Świderski!
authorTed Kremenek <kremenek@apple.com>
Mon, 13 Sep 2010 22:25:59 +0000 (22:25 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 13 Sep 2010 22:25:59 +0000 (22:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113799 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/Support/BumpVector.h

index 7cd481238f8171f6609d8e19e8fe78133add811e..020e858b9b6d41c64429f01269c9e96291e4d4e2 100644 (file)
@@ -155,7 +155,25 @@ public:
     grow(C);
     goto Retry;    
   }
-  
+
+  /// insert - Insert some number of copies of element into a position. Return
+  /// iterator to position after last inserted copy.
+  iterator insert(iterator I, size_t Cnt, const_reference E,
+      BumpVectorContext &C) {
+    assert (I >= Begin && I <= End && "Iterator out of bounds.");
+    if (End + Cnt <= Capacity) {
+    Retry:
+      move_range_right(I, End, Cnt);
+      construct_range(I, I + Cnt, E);
+      End += Cnt;
+      return I + Cnt;
+    }
+    ptrdiff_t D = I - Begin;
+    grow(C, size() + Cnt);
+    I = Begin + D;
+    goto Retry;
+  }
+
   void reserve(BumpVectorContext &C, unsigned N) {
     if (unsigned(Capacity-Begin) < N)
       grow(C, N);
@@ -181,6 +199,14 @@ private:
       E->~T();
     }
   }
+
+  void move_range_right(T *S, T *E, size_t D) {
+    for (T *I = E + D - 1, *IL = S + D - 1; I != IL; --I) {
+      --E;
+      new (I) T(*E);
+      E->~T();
+    }
+  }
 };
   
 // Define this out-of-line to dissuade the C++ compiler from inlining it.