Skip to content

Commit

Permalink
In Twine::str(), if the Twine stores only a std::string, just return …
Browse files Browse the repository at this point in the history
…a direct copy of that instead of first copying to a SmallString and converting that to a std::string. Also fix some indentation.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135267 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
fvbommel committed Jul 15, 2011
1 parent 0bd9d3a commit 331dbca
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/Support/Twine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
using namespace llvm;

std::string Twine::str() const {
// If we're storing only a std::string, just return it.
if (LHSKind == StdStringKind && RHSKind == EmptyKind)
return *static_cast<const std::string*>(LHS);

// Otherwise, flatten and copy the contents first.
SmallString<256> Vec;
return toStringRef(Vec).str();
}
Expand All @@ -37,9 +42,9 @@ StringRef Twine::toNullTerminatedStringRef(SmallVectorImpl<char> &Out) const {
// Already null terminated, yay!
return StringRef(static_cast<const char*>(LHS));
case StdStringKind: {
const std::string *str = static_cast<const std::string*>(LHS);
return StringRef(str->c_str(), str->size());
}
const std::string *str = static_cast<const std::string*>(LHS);
return StringRef(str->c_str(), str->size());
}
default:
break;
}
Expand Down

0 comments on commit 331dbca

Please sign in to comment.