]> granicus.if.org Git - clang/commitdiff
Replace some const std::string & with llvm::StringRef or std::string
authorYaron Keren <yaron.keren@gmail.com>
Fri, 3 Jul 2015 05:09:59 +0000 (05:09 +0000)
committerYaron Keren <yaron.keren@gmail.com>
Fri, 3 Jul 2015 05:09:59 +0000 (05:09 +0000)
and std::move to avoid implicit std::string construction.

Part 1/2.

Patch by Eugene Kosov.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241319 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/ASTMatchers/ASTMatchers.h
include/clang/ASTMatchers/ASTMatchersInternal.h
include/clang/ASTMatchers/Dynamic/VariantValue.h
include/clang/Frontend/CompilerInstance.h
lib/ASTMatchers/Dynamic/Parser.cpp
lib/ASTMatchers/Dynamic/VariantValue.cpp
lib/Frontend/CompilerInstance.cpp

index e7a97a7ff7458f5910c15138e32325e262883451..281d6370e5c8f16a7a2ee901c1a28ae74c7f00fc 100644 (file)
@@ -112,7 +112,7 @@ private:
 ///
 /// FIXME: Do we want to support this now that we have bind()?
 template <typename T>
-internal::Matcher<T> id(const std::string &ID,
+internal::Matcher<T> id(StringRef ID,
                         const internal::BindableMatcher<T> &InnerMatcher) {
   return InnerMatcher.bind(ID);
 }
index cbaa4ba27ce7e5f85a02290c8f7f97788fe688f8..b494647d79bcd4f0cc8b2d6e7fb8fb96519018e2 100644 (file)
@@ -140,8 +140,7 @@ public:
   };
 
   /// \brief Add a binding from an id to a node.
-  void setBinding(const std::string &Id,
-                  const ast_type_traits::DynTypedNode &DynNode) {
+  void setBinding(StringRef Id, const ast_type_traits::DynTypedNode &DynNode) {
     if (Bindings.empty())
       Bindings.emplace_back();
     for (BoundNodesMap &Binding : Bindings)
index 78aa9dc82a982c4fab3289c41c8fc871d3d3f442..c391b24a3330e005e0116ea42847853da75be662 100644 (file)
@@ -242,7 +242,7 @@ struct VariantMatcher::TypedMatcherOps final : VariantMatcher::MatcherOps {
 ///
 /// Supported types:
 ///  - \c unsigned
-///  - \c std::string
+///  - \c llvm::StringRef
 ///  - \c VariantMatcher (\c DynTypedMatcher / \c Matcher<T>)
 class VariantValue {
 public:
@@ -254,7 +254,7 @@ public:
 
   /// \brief Specific constructors for each supported type.
   VariantValue(unsigned Unsigned);
-  VariantValue(const std::string &String);
+  VariantValue(StringRef String);
   VariantValue(const VariantMatcher &Matchers);
 
   /// \brief Returns true iff this is not an empty value.
@@ -269,7 +269,7 @@ public:
   /// \brief String value functions.
   bool isString() const;
   const std::string &getString() const;
-  void setString(const std::string &String);
+  void setString(StringRef String);
 
   /// \brief Matcher value functions.
   bool isMatcher() const;
index 9cd806c99b85ad8e328d8cdd05d9c24e9ad16555..084d876a2ae273bbb3134a18389eceb16ed864f0 100644 (file)
@@ -157,9 +157,10 @@ class CompilerInstance : public ModuleLoader {
     std::string TempFilename;
     std::unique_ptr<raw_ostream> OS;
 
-    OutputFile(const std::string &filename, const std::string &tempFilename,
+    OutputFile(std::string filename, std::string tempFilename,
                std::unique_ptr<raw_ostream> OS)
-        : Filename(filename), TempFilename(tempFilename), OS(std::move(OS)) {}
+        : Filename(std::move(filename)), TempFilename(std::move(tempFilename)),
+          OS(std::move(OS)) {}
     OutputFile(OutputFile &&O)
         : Filename(std::move(O.Filename)),
           TempFilename(std::move(O.TempFilename)), OS(std::move(O.OS)) {}
@@ -614,7 +615,7 @@ public:
   ///
   /// \return - The new object on success, or null on failure.
   static IntrusiveRefCntPtr<ASTReader> createPCHExternalASTSource(
-      StringRef Path, const std::string &Sysroot, bool DisablePCHValidation,
+      StringRef Path, StringRef Sysroot, bool DisablePCHValidation,
       bool AllowPCHWithCompilerErrors, Preprocessor &PP, ASTContext &Context,
       const PCHContainerOperations &PCHContainerOps,
       void *DeserializationListener, bool OwnDeserializationListener,
@@ -627,11 +628,9 @@ public:
 
   /// Create a code completion consumer to print code completion results, at
   /// \p Filename, \p Line, and \p Column, to the given output stream \p OS.
-  static CodeCompleteConsumer *
-  createCodeCompletionConsumer(Preprocessor &PP, const std::string &Filename,
-                               unsigned Line, unsigned Column,
-                               const CodeCompleteOptions &Opts,
-                               raw_ostream &OS);
+  static CodeCompleteConsumer *createCodeCompletionConsumer(
+      Preprocessor &PP, StringRef Filename, unsigned Line, unsigned Column,
+      const CodeCompleteOptions &Opts, raw_ostream &OS);
 
   /// \brief Create the Sema object to be used for parsing.
   void createSema(TranslationUnitKind TUKind,
index 9930c530c081407a5524a93a4d02c0088e99677a..96a78cd9f8fa93d674412e2333078fc7dd99028e 100644 (file)
@@ -216,7 +216,7 @@ private:
       if (Code[Length] == Marker) {
         Result->Kind = TokenInfo::TK_Literal;
         Result->Text = Code.substr(0, Length + 1);
-        Result->Value = Code.substr(1, Length - 1).str();
+        Result->Value = Code.substr(1, Length - 1);
         Code = Code.drop_front(Length + 1);
         return;
       }
index a88b707012341372cc4319912fdd7f7e39697866..9d8be47005810d7c66b48f6f8aa5ce1938d3f6f5 100644 (file)
@@ -249,7 +249,7 @@ VariantValue::VariantValue(unsigned Unsigned) : Type(VT_Nothing) {
   setUnsigned(Unsigned);
 }
 
-VariantValue::VariantValue(const std::string &String) : Type(VT_Nothing) {
+VariantValue::VariantValue(StringRef String) : Type(VT_Nothing) {
   setString(String);
 }
 
@@ -319,7 +319,7 @@ const std::string &VariantValue::getString() const {
   return *Value.String;
 }
 
-void VariantValue::setString(const std::string &NewValue) {
+void VariantValue::setString(StringRef NewValue) {
   reset();
   Type = VT_String;
   Value.String = new std::string(NewValue);
index 6b0fed6761823094268407118c2a56ac7258fd8c..f42198df4f8ad06b21dab4f8c199ef8159a85f07 100644 (file)
@@ -405,7 +405,7 @@ void CompilerInstance::createPCHExternalASTSource(
 }
 
 IntrusiveRefCntPtr<ASTReader> CompilerInstance::createPCHExternalASTSource(
-    StringRef Path, const std::string &Sysroot, bool DisablePCHValidation,
+    StringRef Path, StringRef Sysroot, bool DisablePCHValidation,
     bool AllowPCHWithCompilerErrors, Preprocessor &PP, ASTContext &Context,
     const PCHContainerOperations &PCHContainerOps,
     void *DeserializationListener, bool OwnDeserializationListener,
@@ -413,7 +413,7 @@ IntrusiveRefCntPtr<ASTReader> CompilerInstance::createPCHExternalASTSource(
   HeaderSearchOptions &HSOpts = PP.getHeaderSearchInfo().getHeaderSearchOpts();
 
   IntrusiveRefCntPtr<ASTReader> Reader(new ASTReader(
-      PP, Context, PCHContainerOps, Sysroot.empty() ? "" : Sysroot.c_str(),
+      PP, Context, PCHContainerOps, Sysroot.empty() ? "" : Sysroot.data(),
       DisablePCHValidation, AllowPCHWithCompilerErrors,
       /*AllowConfigurationMismatch*/ false, HSOpts.ModulesValidateSystemHeaders,
       UseGlobalModuleIndex));
@@ -502,7 +502,7 @@ void CompilerInstance::createFrontendTimer() {
 
 CodeCompleteConsumer *
 CompilerInstance::createCodeCompletionConsumer(Preprocessor &PP,
-                                               const std::string &Filename,
+                                               StringRef Filename,
                                                unsigned Line,
                                                unsigned Column,
                                                const CodeCompleteOptions &Opts,