[llvm-commits] [llvm] r158643 - in /llvm/trunk: include/llvm/ADT/SmallVector.h unittests/ADT/SmallVectorTest.cpp
Benjamin Kramer
benny.kra at googlemail.com
Sun Jun 17 04:52:22 PDT 2012
Author: d0k
Date: Sun Jun 17 06:52:22 2012
New Revision: 158643
URL: http://llvm.org/viewvc/llvm-project?rev=158643&view=rev
Log:
SmallVector: return a valid iterator for the rare case of inserting an empty range into a SmallVector.
Patch by Johannes Schaub!
Modified:
llvm/trunk/include/llvm/ADT/SmallVector.h
llvm/trunk/unittests/ADT/SmallVectorTest.cpp
Modified: llvm/trunk/include/llvm/ADT/SmallVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallVector.h?rev=158643&r1=158642&r2=158643&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/SmallVector.h (original)
+++ llvm/trunk/include/llvm/ADT/SmallVector.h Sun Jun 17 06:52:22 2012
@@ -542,7 +542,7 @@
iterator insert(iterator I, size_type NumToInsert, const T &Elt) {
if (I == this->end()) { // Important special case for empty vector.
append(NumToInsert, Elt);
- return this->end()-1;
+ return NumToInsert == 0 ? this->end() : this->end()-1;
}
// Convert iterator to elt# to avoid invalidating iterator when we reserve()
@@ -590,7 +590,7 @@
iterator insert(iterator I, ItTy From, ItTy To) {
if (I == this->end()) { // Important special case for empty vector.
append(From, To);
- return this->end()-1;
+ return From == To ? this->end() : this->end()-1;
}
size_t NumToInsert = std::distance(From, To);
Modified: llvm/trunk/unittests/ADT/SmallVectorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/SmallVectorTest.cpp?rev=158643&r1=158642&r2=158643&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/SmallVectorTest.cpp (original)
+++ llvm/trunk/unittests/ADT/SmallVectorTest.cpp Sun Jun 17 06:52:22 2012
@@ -353,6 +353,9 @@
makeSequence(theVector, 10, 15);
theVector.insert(theVector.begin() + 1, 2, Constructable(16));
assertValuesInOrder(theVector, 8u, 10, 16, 16, 11, 12, 13, 14, 15);
+
+ EXPECT_EQ(theVector.end(),
+ theVector.insert(theVector.end(), 0, Constructable(42)));
}
// Insert range.
@@ -362,6 +365,10 @@
makeSequence(theVector, 1, 3);
theVector.insert(theVector.begin() + 1, 3, Constructable(77));
assertValuesInOrder(theVector, 6u, 1, 77, 77, 77, 2, 3);
+
+ EXPECT_EQ(theVector.end(), theVector.insert(theVector.end(),
+ theVector.begin(),
+ theVector.begin()));
}
// Comparison tests.
More information about the llvm-commits
mailing list