marsupial created this revision.
marsupial added reviewers: eugene, boris.
marsupial added a project: clang.
marsupial updated this revision to Diff 138982.

Arguments passed to HeaderSearchOptions methods are stored as std::strings, 
having them converted to a StringRef at the call site can result in unnecessary 
conversions and copies.


https://reviews.llvm.org/D44643

Files:
  include/clang/Lex/HeaderSearchOptions.h


Index: include/clang/Lex/HeaderSearchOptions.h
===================================================================
--- include/clang/Lex/HeaderSearchOptions.h
+++ include/clang/Lex/HeaderSearchOptions.h
@@ -203,34 +203,35 @@
 
   unsigned ModulesHashContent : 1;
 
-  HeaderSearchOptions(StringRef _Sysroot = "/")
-      : Sysroot(_Sysroot), ModuleFormat("raw"), DisableModuleHash(false),
-        ImplicitModuleMaps(false), ModuleMapFileHomeIsCwd(false),
-        UseBuiltinIncludes(true), UseStandardSystemIncludes(true),
-        UseStandardCXXIncludes(true), UseLibcxx(false), Verbose(false),
+  HeaderSearchOptions(std::string _Sysroot = "/")
+      : Sysroot(std::move(_Sysroot)), ModuleFormat("raw"),
+        DisableModuleHash(false), ImplicitModuleMaps(false),
+        ModuleMapFileHomeIsCwd(false), UseBuiltinIncludes(true),
+        UseStandardSystemIncludes(true), UseStandardCXXIncludes(true),
+        UseLibcxx(false), Verbose(false),
         ModulesValidateOncePerBuildSession(false),
         ModulesValidateSystemHeaders(false), UseDebugInfo(false),
         ModulesValidateDiagnosticOptions(true), ModulesHashContent(false) {}
 
   /// AddPath - Add the \p Path path to the specified \p Group list.
-  void AddPath(StringRef Path, frontend::IncludeDirGroup Group,
+  void AddPath(std::string Path, frontend::IncludeDirGroup Group,
                bool IsFramework, bool IgnoreSysRoot) {
-    UserEntries.emplace_back(Path, Group, IsFramework, IgnoreSysRoot);
+    UserEntries.emplace_back(std::move(Path), Group, IsFramework, 
IgnoreSysRoot);
   }
 
   /// AddSystemHeaderPrefix - Override whether \#include directives naming a
   /// path starting with \p Prefix should be considered as naming a system
   /// header.
-  void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
-    SystemHeaderPrefixes.emplace_back(Prefix, IsSystemHeader);
+  void AddSystemHeaderPrefix(std::string Prefix, bool IsSystemHeader) {
+    SystemHeaderPrefixes.emplace_back(std::move(Prefix), IsSystemHeader);
   }
 
-  void AddVFSOverlayFile(StringRef Name) {
-    VFSOverlayFiles.push_back(Name);
+  void AddVFSOverlayFile(std::string Name) {
+    VFSOverlayFiles.emplace_back(std::move(Name));
   }
 
-  void AddPrebuiltModulePath(StringRef Name) {
-    PrebuiltModulePaths.push_back(Name);
+  void AddPrebuiltModulePath(std::string Name) {
+    PrebuiltModulePaths.emplace_back(std::move(Name));
   }
 };
 


Index: include/clang/Lex/HeaderSearchOptions.h
===================================================================
--- include/clang/Lex/HeaderSearchOptions.h
+++ include/clang/Lex/HeaderSearchOptions.h
@@ -203,34 +203,35 @@
 
   unsigned ModulesHashContent : 1;
 
-  HeaderSearchOptions(StringRef _Sysroot = "/")
-      : Sysroot(_Sysroot), ModuleFormat("raw"), DisableModuleHash(false),
-        ImplicitModuleMaps(false), ModuleMapFileHomeIsCwd(false),
-        UseBuiltinIncludes(true), UseStandardSystemIncludes(true),
-        UseStandardCXXIncludes(true), UseLibcxx(false), Verbose(false),
+  HeaderSearchOptions(std::string _Sysroot = "/")
+      : Sysroot(std::move(_Sysroot)), ModuleFormat("raw"),
+        DisableModuleHash(false), ImplicitModuleMaps(false),
+        ModuleMapFileHomeIsCwd(false), UseBuiltinIncludes(true),
+        UseStandardSystemIncludes(true), UseStandardCXXIncludes(true),
+        UseLibcxx(false), Verbose(false),
         ModulesValidateOncePerBuildSession(false),
         ModulesValidateSystemHeaders(false), UseDebugInfo(false),
         ModulesValidateDiagnosticOptions(true), ModulesHashContent(false) {}
 
   /// AddPath - Add the \p Path path to the specified \p Group list.
-  void AddPath(StringRef Path, frontend::IncludeDirGroup Group,
+  void AddPath(std::string Path, frontend::IncludeDirGroup Group,
                bool IsFramework, bool IgnoreSysRoot) {
-    UserEntries.emplace_back(Path, Group, IsFramework, IgnoreSysRoot);
+    UserEntries.emplace_back(std::move(Path), Group, IsFramework, IgnoreSysRoot);
   }
 
   /// AddSystemHeaderPrefix - Override whether \#include directives naming a
   /// path starting with \p Prefix should be considered as naming a system
   /// header.
-  void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
-    SystemHeaderPrefixes.emplace_back(Prefix, IsSystemHeader);
+  void AddSystemHeaderPrefix(std::string Prefix, bool IsSystemHeader) {
+    SystemHeaderPrefixes.emplace_back(std::move(Prefix), IsSystemHeader);
   }
 
-  void AddVFSOverlayFile(StringRef Name) {
-    VFSOverlayFiles.push_back(Name);
+  void AddVFSOverlayFile(std::string Name) {
+    VFSOverlayFiles.emplace_back(std::move(Name));
   }
 
-  void AddPrebuiltModulePath(StringRef Name) {
-    PrebuiltModulePaths.push_back(Name);
+  void AddPrebuiltModulePath(std::string Name) {
+    PrebuiltModulePaths.emplace_back(std::move(Name));
   }
 };
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to