[llvm-branch-commits] [llvm] c224a83 - ADT: Reduce code duplication in SmallVector::resize by using pop_back_n, NFC

Duncan P. N. Exon Smith via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Jan 13 20:58:35 PST 2021


Author: Duncan P. N. Exon Smith
Date: 2021-01-13T20:50:00-08:00
New Revision: c224a834583ccbb3f8e8047d409ef3bf356abc01

URL: https://github.com/llvm/llvm-project/commit/c224a834583ccbb3f8e8047d409ef3bf356abc01
DIFF: https://github.com/llvm/llvm-project/commit/c224a834583ccbb3f8e8047d409ef3bf356abc01.diff

LOG: ADT: Reduce code duplication in SmallVector::resize by using pop_back_n, NFC

Added: 
    

Modified: 
    llvm/include/llvm/ADT/SmallVector.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
index ac445e556ba1..32c149c4993f 100644
--- a/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm/include/llvm/ADT/SmallVector.h
@@ -545,8 +545,7 @@ class SmallVectorImpl : public SmallVectorTemplateBase<T> {
 private:
   template <bool ForOverwrite> void resizeImpl(size_type N) {
     if (N < this->size()) {
-      this->destroy_range(this->begin()+N, this->end());
-      this->set_size(N);
+      this->pop_back_n(this->size() - N);
     } else if (N > this->size()) {
       if (this->capacity() < N)
         this->grow(N);
@@ -570,8 +569,7 @@ class SmallVectorImpl : public SmallVectorTemplateBase<T> {
       return;
 
     if (N < this->size()) {
-      this->destroy_range(this->begin()+N, this->end());
-      this->set_size(N);
+      this->pop_back_n(this->size() - N);
       return;
     }
 


        


More information about the llvm-branch-commits mailing list