diff options
author | Frits van Bommel <fvbommel@gmail.com> | 2011-07-15 11:05:37 +0000 |
---|---|---|
committer | Frits van Bommel <fvbommel@gmail.com> | 2011-07-15 11:05:37 +0000 |
commit | f8bf4c213ae62aa4dc1e6fa431d510f2f4547918 (patch) | |
tree | dee61c3df703bda5dfe489df72591ef4397aa0eb /llvm/lib/Support/Twine.cpp | |
parent | c5d10504d5767896f38c3c4d2ae966348f0aa2cf (diff) | |
download | bcm5719-llvm-f8bf4c213ae62aa4dc1e6fa431d510f2f4547918.tar.gz bcm5719-llvm-f8bf4c213ae62aa4dc1e6fa431d510f2f4547918.zip |
In Twine::str(), if the Twine stores only a std::string, just return a direct copy of that instead of first copying to a SmallString and converting that to a std::string. Also fix some indentation.
llvm-svn: 135267
Diffstat (limited to 'llvm/lib/Support/Twine.cpp')
-rw-r--r-- | llvm/lib/Support/Twine.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/llvm/lib/Support/Twine.cpp b/llvm/lib/Support/Twine.cpp index 75cea2961a9..d62123cc985 100644 --- a/llvm/lib/Support/Twine.cpp +++ b/llvm/lib/Support/Twine.cpp @@ -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(); } @@ -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; } |