diff options
author | Chris Lattner <sabre@nondot.org> | 2009-12-15 08:34:01 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-12-15 08:34:01 +0000 |
commit | 4a5129c700a76bf5c4b7f2aa9c362496fb6d8bd6 (patch) | |
tree | 848935b745ce02e104c63245a5a96c443fd5cab2 /include/llvm/ADT/SmallVector.h | |
parent | 10aaf05c304e259dbb853a37d491fdc4ea54c9b1 (diff) | |
download | external_llvm-4a5129c700a76bf5c4b7f2aa9c362496fb6d8bd6.zip external_llvm-4a5129c700a76bf5c4b7f2aa9c362496fb6d8bd6.tar.gz external_llvm-4a5129c700a76bf5c4b7f2aa9c362496fb6d8bd6.tar.bz2 |
a few improvements:
1. Use std::equal instead of reinventing it.
2. don't run dtors in destroy_range if element is pod-like.
3. Use isPodLike to decide between memcpy/uninitialized_copy
instead of is_class. isPodLike is more generous in some cases.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91427 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/SmallVector.h')
-rw-r--r-- | include/llvm/ADT/SmallVector.h | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/include/llvm/ADT/SmallVector.h b/include/llvm/ADT/SmallVector.h index 69c25d0..b16649e 100644 --- a/include/llvm/ADT/SmallVector.h +++ b/include/llvm/ADT/SmallVector.h @@ -402,11 +402,7 @@ public: bool operator==(const SmallVectorImpl &RHS) const { if (size() != RHS.size()) return false; - for (const T *This = begin(), *That = RHS.begin(), *E = end(); - This != E; ++This, ++That) - if (*This != *That) - return false; - return true; + return std::equal(begin(), end(), RHS.begin()); } bool operator!=(const SmallVectorImpl &RHS) const { return !(*this == RHS); } @@ -440,7 +436,9 @@ private: } void destroy_range(T *S, T *E) { - // TODO: POD + // No need to do a destroy loop for POD's. + if (isPodLike<T>::value) return; + while (S != E) { --E; E->~T(); @@ -459,11 +457,11 @@ void SmallVectorImpl<T>::grow(size_t MinSize) { T *NewElts = static_cast<T*>(operator new(NewCapacity*sizeof(T))); // Copy the elements over. - if (is_class<T>::value) - std::uninitialized_copy(begin(), end(), NewElts); - else - // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove). + if (isPodLike<T>::value) + // Use memcpy for PODs: std::uninitialized_copy optimizes to memmove. memcpy(NewElts, begin(), CurSize * sizeof(T)); + else + std::uninitialized_copy(begin(), end(), NewElts); // Destroy the original elements. destroy_range(begin(), end()); |