From ed8ba2e58e6ad9069feeba7bfca60b8873d23743 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Sun, 9 Mar 2014 06:17:01 +0000 Subject: 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 --- include/llvm/ADT/SmallString.h | 50 ++++++++++++------------------------------ include/llvm/ADT/SmallVector.h | 10 +++++---- 2 files changed, 20 insertions(+), 40 deletions(-) (limited to 'include/llvm/ADT') diff --git a/include/llvm/ADT/SmallString.h b/include/llvm/ADT/SmallString.h index e569f54481..740a0a5cd8 100644 --- a/include/llvm/ADT/SmallString.h +++ b/include/llvm/ADT/SmallString.h @@ -28,30 +28,18 @@ public: SmallString() {} /// Initialize from a StringRef. - SmallString(StringRef S) : SmallVector(S.begin(), S.end()) {} + /*implicit*/ SmallString(StringRef S) : SmallVector(S.begin(), S.end()) {} /// Initialize with a range. template SmallString(ItTy S, ItTy E) : SmallVector(S, E) {} - // Note that in order to add new overloads for append & assign, we have to - // duplicate the inherited versions so as not to inadvertently hide them. - /// @} /// @name String Assignment /// @{ - /// Assign from a repeated element. - void assign(size_t NumElts, char Elt) { - this->SmallVectorImpl::assign(NumElts, Elt); - } - - /// Assign from an iterator pair. - template - void assign(in_iter S, in_iter E) { - this->clear(); - SmallVectorImpl::append(S, E); - } + // Provide assign from SmallVectorImpl + using SmallVectorImpl::assign; /// Assign from a StringRef. void assign(StringRef RHS) { @@ -65,20 +53,7 @@ public: SmallVectorImpl::append(RHS.begin(), RHS.end()); } - /// @} - /// @name String Concatenation - /// @{ - - /// Append from an iterator pair. - template - void append(in_iter S, in_iter E) { - SmallVectorImpl::append(S, E); - } - - void append(size_t NumInputs, char Elt) { - SmallVectorImpl::append(NumInputs, Elt); - } - + using SmallVectorImpl::append; /// Append from a StringRef. void append(StringRef RHS) { @@ -94,12 +69,6 @@ public: /// @name String Comparison /// @{ - /// Check for string equality. This is more efficient than compare() when - /// the relative ordering of inequal strings isn't needed. - bool equals(StringRef RHS) const { - return str().equals(RHS); - } - /// Check for string equality, ignoring case. bool equals_lower(StringRef RHS) const { return str().equals_lower(RHS); @@ -276,6 +245,9 @@ public: /// Implicit conversion to StringRef. operator StringRef() const { return str(); } + // Provide op= for SmallVectorImpl + using SmallVectorImpl::operator=; + // Extra operators. const SmallString &operator=(StringRef RHS) { this->clear(); @@ -283,9 +255,15 @@ public: } SmallString &operator+=(StringRef RHS) { - this->append(RHS.begin(), RHS.end()); + append(RHS.begin(), RHS.end()); return *this; } + + SmallString &operator+=(const SmallVectorImpl &RHS) { + append(RHS.begin(), RHS.end()); + return *this; + } + SmallString &operator+=(char C) { this->push_back(C); return *this; diff --git a/include/llvm/ADT/SmallVector.h b/include/llvm/ADT/SmallVector.h index 2a5168c261..e5e53d1dd6 100644 --- a/include/llvm/ADT/SmallVector.h +++ b/include/llvm/ADT/SmallVector.h @@ -451,10 +451,12 @@ public: void assign(unsigned NumElts, const T &Elt) { clear(); - if (this->capacity() < NumElts) - this->grow(NumElts); - this->setEnd(this->begin()+NumElts); - std::uninitialized_fill(this->begin(), this->end(), Elt); + append(NumElts, Elt); + } + + template void assign(in_iter S, in_iter E) { + clear(); + append(S, E); } iterator erase(iterator I) { -- cgit v1.2.3