llvm.org GIT mirror llvm / 3e07f8a
Revert "Clean up SmallString a bit" This reverts commit r203374. Ambiguities in assign... oh well. I'm just going to revert this and probably not try to recommit it as it's not terribly important. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203375 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 /*implicit*/ SmallString(StringRef S) : SmallVector(S.begin(), S.end()) {}
30 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
3639 /// @}
3740 /// @name String Assignment
3841 /// @{
3942
40 // Provide assign from SmallVectorImpl
41 using SmallVectorImpl::assign;
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 }
4254
4355 /// Assign from a StringRef.
4456 void assign(StringRef RHS) {
5264 SmallVectorImpl::append(RHS.begin(), RHS.end());
5365 }
5466
55 using SmallVectorImpl::append;
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
5681
5782 /// Append from a StringRef.
5883 void append(StringRef RHS) {
6792 /// @}
6893 /// @name String Comparison
6994 /// @{
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 }
70101
71102 /// Check for string equality, ignoring case.
72103 bool equals_lower(StringRef RHS) const {
244275 /// Implicit conversion to StringRef.
245276 operator StringRef() const { return str(); }
246277
247 // Provide op= for SmallVectorImpl
248 using SmallVectorImpl::operator=;
249
250278 // Extra operators.
251279 const SmallString &operator=(StringRef RHS) {
252280 this->clear();
254282 }
255283
256284 SmallString &operator+=(StringRef RHS) {
257 append(RHS.begin(), RHS.end());
285 this->append(RHS.begin(), RHS.end());
258286 return *this;
259287 }
260
261 SmallString &operator+=(const SmallVectorImpl &RHS) {
262 append(RHS.begin(), RHS.end());
263 return *this;
264 }
265
266288 SmallString &operator+=(char C) {
267289 this->push_back(C);
268290 return *this;
450450
451451 void assign(unsigned NumElts, const T &Elt) {
452452 clear();
453 append(NumElts, Elt);
454 }
455
456 template void assign(in_iter S, in_iter E) {
457 clear();
458 append(S, E);
453 if (this->capacity() < NumElts)
454 this->grow(NumElts);
455 this->setEnd(this->begin()+NumElts);
456 std::uninitialized_fill(this->begin(), this->end(), Elt);
459457 }
460458
461459 iterator erase(iterator I) {
4949
5050 bool operator==(const DILineInfo &RHS) const {
5151 return Line == RHS.Line && Column == RHS.Column &&
52 FileName == RHS.FileName && FunctionName == RHS.FunctionName;
52 FileName.equals(RHS.FileName) &&
53 FunctionName.equals(RHS.FunctionName);
5354 }
5455 bool operator!=(const DILineInfo &RHS) const {
5556 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
5259 TEST_F(SmallStringTest, AssignStringRef) {
5360 StringRef abc = "abc";
5461 theString.assign(abc);
7683 StringRef abc = "abc";
7784 theString.append(abc);
7885 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;
9686 EXPECT_EQ(6u, theString.size());
9787 EXPECT_STREQ("abcabc", theString.c_str());
9888 }
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
351340 // Erase a single element
352341 TYPED_TEST(SmallVectorTest, EraseTest) {
353342 SCOPED_TRACE("EraseTest");