From: Frits van Bommel Date: Fri, 15 Jul 2011 11:05:37 +0000 (+0000) Subject: In Twine::str(), if the Twine stores only a std::string, just return a direct copy... X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=331dbca73db75bbb87fcd81e2b8a68c9195de8b5;p=oota-llvm.git 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135267 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Support/Twine.cpp b/lib/Support/Twine.cpp index 75cea2961a9..d62123cc985 100644 --- a/lib/Support/Twine.cpp +++ b/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(LHS); + + // Otherwise, flatten and copy the contents first. SmallString<256> Vec; return toStringRef(Vec).str(); } @@ -37,9 +42,9 @@ StringRef Twine::toNullTerminatedStringRef(SmallVectorImpl &Out) const { // Already null terminated, yay! return StringRef(static_cast(LHS)); case StdStringKind: { - const std::string *str = static_cast(LHS); - return StringRef(str->c_str(), str->size()); - } + const std::string *str = static_cast(LHS); + return StringRef(str->c_str(), str->size()); + } default: break; }