[llvm-branch-commits] [llvm] 3f98b66 - ADT: Reduce code duplication in SmallVector by reusing reserve, NFC

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


Author: Duncan P. N. Exon Smith
Date: 2021-01-13T20:52:57-08:00
New Revision: 3f98b66f23f9844a61f63ee00a81b9914f9a039d

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

LOG: ADT: Reduce code duplication in SmallVector by reusing reserve, 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 32c149c4993f..0103798a9a6b 100644
--- a/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm/include/llvm/ADT/SmallVector.h
@@ -547,8 +547,7 @@ class SmallVectorImpl : public SmallVectorTemplateBase<T> {
     if (N < this->size()) {
       this->pop_back_n(this->size() - N);
     } else if (N > this->size()) {
-      if (this->capacity() < N)
-        this->grow(N);
+      this->reserve(N);
       for (auto I = this->end(), E = this->begin() + N; I != E; ++I)
         if (ForOverwrite)
           new (&*I) T;
@@ -628,8 +627,7 @@ class SmallVectorImpl : public SmallVectorTemplateBase<T> {
   void assign(size_type NumElts, const T &Elt) {
     this->assertSafeToReferenceAfterResize(&Elt, 0);
     clear();
-    if (this->capacity() < NumElts)
-      this->grow(NumElts);
+    this->reserve(NumElts);
     this->set_size(NumElts);
     std::uninitialized_fill(this->begin(), this->end(), Elt);
   }


        


More information about the llvm-branch-commits mailing list