[PATCH] D90576: [ADT] Add SmallVector::pop_back_n
Nathan James via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 3 06:57:27 PST 2020
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG97e8da45f945: [ADT] Add SmallVector::pop_back_n (authored by njames93).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D90576/new/
https://reviews.llvm.org/D90576
Files:
llvm/include/llvm/ADT/SmallVector.h
llvm/unittests/ADT/SmallVectorTest.cpp
Index: llvm/unittests/ADT/SmallVectorTest.cpp
===================================================================
--- llvm/unittests/ADT/SmallVectorTest.cpp
+++ llvm/unittests/ADT/SmallVectorTest.cpp
@@ -261,8 +261,7 @@
this->assertValuesInOrder(this->theVector, 2u, 2, 1);
// Pop remaining elements
- this->theVector.pop_back();
- this->theVector.pop_back();
+ this->theVector.pop_back_n(2);
this->assertEmpty(this->theVector);
// Check number of constructor calls. Should be 2 for each list element,
Index: llvm/include/llvm/ADT/SmallVector.h
===================================================================
--- llvm/include/llvm/ADT/SmallVector.h
+++ llvm/include/llvm/ADT/SmallVector.h
@@ -424,6 +424,12 @@
this->grow(N);
}
+ void pop_back_n(size_type NumItems) {
+ assert(this->size() >= NumItems);
+ this->destroy_range(this->end() - NumItems, this->end());
+ this->set_size(this->size() - NumItems);
+ }
+
LLVM_NODISCARD T pop_back_val() {
T Result = ::std::move(this->back());
this->pop_back();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90576.302572.patch
Type: text/x-patch
Size: 1061 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201103/ea14ba15/attachment.bin>
More information about the llvm-commits
mailing list