[llvm-commits] [llvm] r91427 - /llvm/trunk/include/llvm/ADT/SmallVector.h
Chris Lattner
sabre at nondot.org
Tue Dec 15 00:34:01 PST 2009
Author: lattner
Date: Tue Dec 15 02:34:01 2009
New Revision: 91427
URL: http://llvm.org/viewvc/llvm-project?rev=91427&view=rev
Log:
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.
Modified:
llvm/trunk/include/llvm/ADT/SmallVector.h
Modified: llvm/trunk/include/llvm/ADT/SmallVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallVector.h?rev=91427&r1=91426&r2=91427&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/SmallVector.h (original)
+++ llvm/trunk/include/llvm/ADT/SmallVector.h Tue Dec 15 02:34:01 2009
@@ -402,11 +402,7 @@
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 @@
}
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 @@
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());
More information about the llvm-commits
mailing list