summaryrefslogtreecommitdiff
path: root/include/llvm/ADT/SmallVector.h
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-03-26 18:53:37 +0000
committerDan Gohman <gohman@apple.com>2010-03-26 18:53:37 +0000
commita7a33fd95f15428b7030ef1b764fcf924d5199c8 (patch)
tree9a70776d5e93a1975d7303bf43ce8ee723c9d62f /include/llvm/ADT/SmallVector.h
parent9a52d0c352c852dc9517430442afc54f53e1d4dd (diff)
downloadllvm-a7a33fd95f15428b7030ef1b764fcf924d5199c8.tar.gz
llvm-a7a33fd95f15428b7030ef1b764fcf924d5199c8.tar.bz2
llvm-a7a33fd95f15428b7030ef1b764fcf924d5199c8.tar.xz
Fix SmallVector's insert to handle non-random-access iterators.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@99633 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/SmallVector.h')
-rw-r--r--include/llvm/ADT/SmallVector.h24
1 files changed, 18 insertions, 6 deletions
diff --git a/include/llvm/ADT/SmallVector.h b/include/llvm/ADT/SmallVector.h
index c2afb7e681..2d79a029d0 100644
--- a/include/llvm/ADT/SmallVector.h
+++ b/include/llvm/ADT/SmallVector.h
@@ -239,11 +239,20 @@ public:
/// starting with "Dest", constructing elements into it as needed.
template<typename It1, typename It2>
static void uninitialized_copy(It1 I, It1 E, It2 Dest) {
- // Use memcpy for PODs: std::uninitialized_copy optimizes to memmove, memcpy
- // is better.
- memcpy(&*Dest, &*I, (E-I)*sizeof(T));
+ // Arbitrary iterator types; just use the basic implementation.
+ std::uninitialized_copy(I, E, Dest);
}
-
+
+ /// uninitialized_copy - Copy the range [I, E) onto the uninitialized memory
+ /// starting with "Dest", constructing elements into it as needed.
+ template<typename T1, typename T2>
+ static void uninitialized_copy(T1 *I, T1 *E, T2 *Dest) {
+ // Use memcpy for PODs iterated by pointers (which includes SmallVector
+ // iterators): std::uninitialized_copy optimizes to memmove, but we can
+ // use memcpy here.
+ memcpy(Dest, I, (E-I)*sizeof(T));
+ }
+
/// grow - double the size of the allocated memory, guaranteeing space for at
/// least one more element or MinSize if specified.
void grow(size_t MinSize = 0) {
@@ -501,10 +510,13 @@ public:
this->uninitialized_copy(I, OldEnd, this->end()-NumOverwritten);
// Replace the overwritten part.
- std::copy(From, From+NumOverwritten, I);
+ for (; NumOverwritten > 0; --NumOverwritten) {
+ *I = *From;
+ ++I; ++From;
+ }
// Insert the non-overwritten middle part.
- this->uninitialized_copy(From+NumOverwritten, To, OldEnd);
+ this->uninitialized_copy(From, To, OldEnd);
return I;
}