From 8c1e37bfbe4d2ffab99df0e9574cad517fd92860 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Mon, 13 Sep 2010 22:25:59 +0000 Subject: [PATCH] =?UTF-8?q?Add=20'insert()'=20to=20BumpVector.=20=20Patch?= =?UTF-8?q?=20by=20Marcin=20=C5=9Awiderski!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit llvm-svn: 113799 --- .../clang/Analysis/Support/BumpVector.h | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Analysis/Support/BumpVector.h b/clang/include/clang/Analysis/Support/BumpVector.h index 7cd481238f81..020e858b9b6d 100644 --- a/clang/include/clang/Analysis/Support/BumpVector.h +++ b/clang/include/clang/Analysis/Support/BumpVector.h @@ -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.