llvm.org GIT mirror llvm / ed8ba2e
Clean up SmallString a bit Move a common utility (assign(iter, iter)) into SmallVector (some of the others could be moved there too, but this one seemed particularly generic) and replace repetitions overrides with using directives. And simplify SmallVector::assign(num, element) while I'm here rather than thrashing these files (that cause everyone to rebuild) again. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203374 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 6 years ago
5 changed file(s) with 49 addition(s) and 49 deletion(s). Raw diff Collapse all Expand all
2727 SmallString() {}
2828
2929 /// Initialize from a StringRef.
30 SmallString(StringRef S) : SmallVector(S.begin(), S.end()) {}
30 /*implicit*/ SmallString(StringRef S) : SmallVector(S.begin(), S.end()) {}
3131
3232 /// Initialize with a range.
3333 template
3434 SmallString(ItTy S, ItTy E) : SmallVector(S, E) {}
3535
36 // Note that in order to add new overloads for append & assign, we have to
37 // duplicate the inherited versions so as not to inadvertently hide them.
38
3936 /// @}
4037 /// @name String Assignment
4138 /// @{
4239
43 /// Assign from a repeated element.
44 void assign(size_t NumElts, char Elt) {
45 this->SmallVectorImpl::assign(NumElts, Elt);
46 }
47
48 /// Assign from an iterator pair.
49 template
50 void assign(in_iter S, in_iter E) {
51 this->clear();
52 SmallVectorImpl::append(S, E);
53 }
40 // Provide assign from SmallVectorImpl
41 using SmallVectorImpl::assign;
5442
5543 /// Assign from a StringRef.
5644 void assign(StringRef RHS) {
6452 SmallVectorImpl::append(RHS.begin(), RHS.end());
6553 }
6654
67 /// @}
68 /// @name String Concatenation
69 /// @{
70
71 /// Append from an iterator pair.
72 template
73 void append(in_iter S, in_iter E) {
74 SmallVectorImpl::append(S, E);
75 }
76
77 void append(size_t NumInputs, char Elt) {
78 SmallVectorImpl::append(NumInputs, Elt);
79 }
80
55 using SmallVectorImpl::append;
8156
8257 /// Append from a StringRef.
8358 void append(StringRef RHS) {
9267 /// @}
9368 /// @name String Comparison
9469 /// @{
95
96 /// Check for string equality. This is more efficient than compare() when
97 /// the relative ordering of inequal strings isn't needed.
98 bool equals(StringRef RHS) const {
99 return str().equals(RHS);
100 }
10170
10271 /// Check for string equality, ignoring case.
10372 bool equals_lower(StringRef RHS) const {
275244 /// Implicit conversion to StringRef.
276245 operator StringRef() const { return str(); }
277246
247 // Provide op= for SmallVectorImpl
248 using SmallVectorImpl::operator=;
249
278250 // Extra operators.
279251 const SmallString &operator=(StringRef RHS) {
280252 this->clear();
282254 }
283255
284256 SmallString &operator+=(StringRef RHS) {
285 this->append(RHS.begin(), RHS.end());
257 append(RHS.begin(), RHS.end());
286258 return *this;
287259 }
260
261 SmallString &operator+=(const SmallVectorImpl &RHS) {
262 append(RHS.begin(), RHS.end());
263 return *this;
264 }
265
288266 SmallString &operator+=(char C) {
289267 this->push_back(C);
290268 return *this;
450450
451451 void assign(unsigned NumElts, const T &Elt) {
452452 clear();
453 if (this->capacity() < NumElts)
454 this->grow(NumElts);
455 this->setEnd(this->begin()+NumElts);
456 std::uninitialized_fill(this->begin(), this->end(), Elt);
453 append(NumElts, Elt);
454 }
455
456 template void assign(in_iter S, in_iter E) {
457 clear();
458 append(S, E);
457459 }
458460
459461 iterator erase(iterator I) {
4949
5050 bool operator==(const DILineInfo &RHS) const {
5151 return Line == RHS.Line && Column == RHS.Column &&
52 FileName.equals(RHS.FileName) &&
53 FunctionName.equals(RHS.FunctionName);
52 FileName == RHS.FileName && FunctionName == RHS.FunctionName;
5453 }
5554 bool operator!=(const DILineInfo &RHS) const {
5655 return !(*this == RHS);
4949 EXPECT_STREQ("aaa", theString.c_str());
5050 }
5151
52 TEST_F(SmallStringTest, AssignIterPair) {
53 StringRef abc = "abc";
54 theString.assign(abc.begin(), abc.end());
55 EXPECT_EQ(3u, theString.size());
56 EXPECT_STREQ("abc", theString.c_str());
57 }
58
5952 TEST_F(SmallStringTest, AssignStringRef) {
6053 StringRef abc = "abc";
6154 theString.assign(abc);
8376 StringRef abc = "abc";
8477 theString.append(abc);
8578 theString.append(abc);
79 EXPECT_EQ(6u, theString.size());
80 EXPECT_STREQ("abcabc", theString.c_str());
81 }
82
83 TEST_F(SmallStringTest, PlusEqualsStringRef) {
84 StringRef abc = "abc";
85 theString += abc;
86 theString += abc;
87 EXPECT_EQ(6u, theString.size());
88 EXPECT_STREQ("abcabc", theString.c_str());
89 }
90
91 TEST_F(SmallStringTest, PlusEqualsSmallVector) {
92 StringRef abc = "abc";
93 SmallVector abcVec(abc.begin(), abc.end());
94 theString += abcVec;
95 theString += abcVec;
8696 EXPECT_EQ(6u, theString.size());
8797 EXPECT_STREQ("abcabc", theString.c_str());
8898 }
337337 this->assertValuesInOrder(this->theVector, 2u, 77, 77);
338338 }
339339
340 TYPED_TEST(SmallVectorTest, AssignIterPair) {
341 SCOPED_TRACE("AssignIterPair");
342
343 std::vector v;
344 v.push_back(1);
345 v.push_back(2);
346 this->theVector.push_back(Constructable(1));
347 this->theVector.assign(v.begin(), v.end());
348 this->assertValuesInOrder(this->theVector, 2u, 1, 2);
349 }
350
340351 // Erase a single element
341352 TYPED_TEST(SmallVectorTest, EraseTest) {
342353 SCOPED_TRACE("EraseTest");