diff options
author | Pete Cooper <peter_cooper@apple.com> | 2012-02-16 04:58:48 +0000 |
---|---|---|
committer | Pete Cooper <peter_cooper@apple.com> | 2012-02-16 04:58:48 +0000 |
commit | d8d110e08ab3fee8d0a2b758c893b7966fd2d3d8 (patch) | |
tree | ccc4b41f960f29292cd07aa70455b7fa3b6ad900 /include | |
parent | c8782a1a53aaef6efc710aa33dd21cce1c8033df (diff) | |
download | external_llvm-d8d110e08ab3fee8d0a2b758c893b7966fd2d3d8.zip external_llvm-d8d110e08ab3fee8d0a2b758c893b7966fd2d3d8.tar.gz external_llvm-d8d110e08ab3fee8d0a2b758c893b7966fd2d3d8.tar.bz2 |
Template specialize SmallVector::push_back based on POD-ness of the type. Reduces clang binary by 188KB
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@150662 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/ADT/SmallVector.h | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/include/llvm/ADT/SmallVector.h b/include/llvm/ADT/SmallVector.h index f99179a..d01cf32 100644 --- a/include/llvm/ADT/SmallVector.h +++ b/include/llvm/ADT/SmallVector.h @@ -194,6 +194,23 @@ protected: /// 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); + +public: + void push_back(const T &Elt) { + if (this->EndX < this->CapacityX) { + Retry: + new (this->end()) T(Elt); + this->setEnd(this->end()+1); + return; + } + this->grow(); + goto Retry; + } + + void pop_back() { + this->setEnd(this->end()-1); + this->end()->~T(); + } }; // Define this out-of-line to dissuade the C++ compiler from inlining it. @@ -255,6 +272,21 @@ protected: void grow(size_t MinSize = 0) { this->grow_pod(MinSize*sizeof(T), sizeof(T)); } +public: + void push_back(const T &Elt) { + if (this->EndX < this->CapacityX) { + Retry: + *this->end() = Elt; + this->setEnd(this->end()+1); + return; + } + this->grow(); + goto Retry; + } + + void pop_back() { + this->setEnd(this->end()-1); + } }; @@ -321,25 +353,9 @@ public: this->grow(N); } - void push_back(const T &Elt) { - if (this->EndX < this->CapacityX) { - Retry: - new (this->end()) T(Elt); - this->setEnd(this->end()+1); - return; - } - this->grow(); - goto Retry; - } - - void pop_back() { - this->setEnd(this->end()-1); - this->end()->~T(); - } - T pop_back_val() { T Result = this->back(); - pop_back(); + this->pop_back(); return Result; } @@ -386,7 +402,7 @@ public: // Shift all elts down one. std::copy(I+1, this->end(), I); // Drop the last elt. - pop_back(); + this->pop_back(); return(N); } @@ -402,7 +418,7 @@ public: iterator insert(iterator I, const T &Elt) { if (I == this->end()) { // Important special case for empty vector. - push_back(Elt); + this->push_back(Elt); return this->end()-1; } |