From: Ted Kremenek Date: Mon, 13 Sep 2010 22:25:59 +0000 (+0000) Subject: Add 'insert()' to BumpVector. Patch by Marcin Świderski! X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=58eb45baff08fd27aeef65fc4e6ae35a4b3a1d90;p=clang Add 'insert()' to BumpVector. Patch by Marcin Świderski! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113799 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Analysis/Support/BumpVector.h b/include/clang/Analysis/Support/BumpVector.h index 7cd481238f..020e858b9b 100644 --- a/include/clang/Analysis/Support/BumpVector.h +++ b/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.