[llvm] d88a5c3 - [SmallString] Remove StringRef indirection for std::string conversion.

Jonas Devlieghere via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 29 13:50:49 PST 2020


Author: Jonas Devlieghere
Date: 2020-01-29T13:49:56-08:00
New Revision: d88a5c398776ed6e4b36b58b79c1b4b56f413f35

URL: https://github.com/llvm/llvm-project/commit/d88a5c398776ed6e4b36b58b79c1b4b56f413f35
DIFF: https://github.com/llvm/llvm-project/commit/d88a5c398776ed6e4b36b58b79c1b4b56f413f35.diff

LOG: [SmallString] Remove StringRef indirection for std::string conversion.

There's no need to go through StringRef to convert a SmallString to a
std::string, the conversion operator can create a std::string directly.

Differential revision: https://reviews.llvm.org/D73640

Added: 
    

Modified: 
    llvm/include/llvm/ADT/SmallString.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/SmallString.h b/llvm/include/llvm/ADT/SmallString.h
index ad0115e8c89a..667cb3b419af 100644
--- a/llvm/include/llvm/ADT/SmallString.h
+++ b/llvm/include/llvm/ADT/SmallString.h
@@ -275,7 +275,9 @@ class SmallString : public SmallVector<char, InternalLen> {
   /// Implicit conversion to StringRef.
   operator StringRef() const { return str(); }
 
-  explicit operator std::string() const { return str().str(); }
+  explicit operator std::string() const {
+    return std::string(this->begin(), this->size());
+  }
 
   // Extra operators.
   const SmallString &operator=(StringRef RHS) {


        


More information about the llvm-commits mailing list