[llvm-commits] [llvm] r135267 - /llvm/trunk/lib/Support/Twine.cpp

Frits van Bommel fvbommel at gmail.com
Fri Jul 15 04:05:38 PDT 2011


Author: fvbommel
Date: Fri Jul 15 06:05:37 2011
New Revision: 135267

URL: http://llvm.org/viewvc/llvm-project?rev=135267&view=rev
Log:
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.

Modified:
    llvm/trunk/lib/Support/Twine.cpp

Modified: llvm/trunk/lib/Support/Twine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Twine.cpp?rev=135267&r1=135266&r2=135267&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Twine.cpp (original)
+++ llvm/trunk/lib/Support/Twine.cpp Fri Jul 15 06:05:37 2011
@@ -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 @@
       // 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;
     }





More information about the llvm-commits mailing list