Repository: kythe/kythe
Pull request #5739 (2023-07-17 20:52:34)

chore(c++): no need to `const&` `llvm::StringRef`s


Patch:
diff --git a/kythe/cxx/indexer/cxx/GraphObserver.h b/kythe/cxx/indexer/cxx/GraphObserver.h
index edf6a1f4c..530c165b0 100644
--- a/kythe/cxx/indexer/cxx/GraphObserver.h
+++ b/kythe/cxx/indexer/cxx/GraphObserver.h
@@ -374,8 +374,7 @@ class GraphObserver {
   /// `clang::BuiltinType::getName(this->getLangOptions())` or the builtin
   /// type constructor.
   /// \return The `NodeId` for `Spelling`.
-  virtual NodeId getNodeIdForBuiltinType(
-      const llvm::StringRef& Spelling) const = 0;
+  virtual NodeId getNodeIdForBuiltinType(llvm::StringRef Spelling) const = 0;
 
   /// \brief Returns the ID for a type node aliasing another type node.
   /// \param AliasName a `NameId` for the alias name.
@@ -602,8 +601,7 @@ class GraphObserver {
   /// \brief Records a node representing a deferred lookup.
   /// \param Node The `NodeId` of the lookup.
   /// \param Name The `Name` for which resolution has been deferred
-  virtual void recordLookupNode(const NodeId& Node,
-                                const llvm::StringRef& Name) {}
+  virtual void recordLookupNode(const NodeId& Node, llvm::StringRef Name) {}
 
   /// \brief Records a parameter relationship.
   /// \param `ParamOfNode` The node this `ParamNode` is the parameter of.
@@ -859,8 +857,7 @@ class GraphObserver {
   /// \param Id The ID of the node to record.
   /// \param NodeKind The kind of the node ("google/protobuf")
   /// \param Compl Whether this node is complete.
-  virtual void recordUserDefinedNode(const NodeId& Id,
-                                     const llvm::StringRef& NodeKind,
+  virtual void recordUserDefinedNode(const NodeId& Id, llvm::StringRef NodeKind,
                                      const absl::optional<Completeness> Compl) {
   }
 
@@ -967,8 +964,7 @@ class GraphObserver {
   /// \brief Records that the specified node is deprecated.
   /// \param NodeId The `NodeId` of the deprecated node.
   /// \param Advice A user-readable message about the deprecation (or empty).
-  virtual void recordDeprecated(const NodeId& NodeId,
-                                const llvm::StringRef& Advice) {}
+  virtual void recordDeprecated(const NodeId& NodeId, llvm::StringRef Advice) {}
 
   /// \brief Records a diagnostic at the given source range
   /// \param Range The source range
@@ -1170,8 +1166,7 @@ class NullGraphObserver : public GraphObserver {
     static void* NullClaimTokenClass;
   };
 
-  NodeId getNodeIdForBuiltinType(
-      const llvm::StringRef& Spelling) const override {
+  NodeId getNodeIdForBuiltinType(llvm::StringRef Spelling) const override {
     return NodeId::CreateUncompressed(getDefaultClaimToken(), "");
   }
 
diff --git a/kythe/cxx/indexer/cxx/KytheGraphObserver.cc b/kythe/cxx/indexer/cxx/KytheGraphObserver.cc
index 7d50c1539..7bad0a7bc 100644
--- a/kythe/cxx/indexer/cxx/KytheGraphObserver.cc
+++ b/kythe/cxx/indexer/cxx/KytheGraphObserver.cc
@@ -438,7 +438,7 @@ void KytheGraphObserver::recordIncludesRange(const Range& source_range,
 }
 
 void KytheGraphObserver::recordUserDefinedNode(
-    const NodeId& node, const llvm::StringRef& kind,
+    const NodeId& node, llvm::StringRef kind,
     const absl::optional<Completeness> completeness) {
   VNameRef node_vname = VNameRefFromNodeId(node);
   recorder_->AddProperty(node_vname, PropertyID::kNodeKind, ConvertRef(kind));
@@ -1080,7 +1080,7 @@ void KytheGraphObserver::recordTVarNode(
 }
 
 void KytheGraphObserver::recordLookupNode(const NodeId& node_id,
-                                          const llvm::StringRef& text) {
+                                          llvm::StringRef text) {
   VNameRef node_vname = VNameRefFromNodeId(node_id);
   recorder_->AddProperty(node_vname, NodeKindID::kLookup);
   recorder_->AddProperty(node_vname, PropertyID::kText, ConvertRef(text));
@@ -1250,7 +1250,7 @@ void KytheGraphObserver::recordVisibility(const NodeId& FieldNodeId,
 }
 
 void KytheGraphObserver::recordDeprecated(const NodeId& NodeId,
-                                          const llvm::StringRef& Advice) {
+                                          llvm::StringRef Advice) {
   const VNameRef node_vname = VNameRefFromNodeId(NodeId);
   recorder_->AddProperty(node_vname, PropertyID::kTagDeprecated,
                          ConvertRef(Advice));
@@ -1278,7 +1278,7 @@ void KytheGraphObserver::recordDiagnostic(const Range& Range,
 }
 
 GraphObserver::NodeId KytheGraphObserver::getNodeIdForBuiltinType(
-    const llvm::StringRef& spelling) const {
+    llvm::StringRef spelling) const {
   const auto& info = builtins_.find(spelling.str());
   if (info == builtins_.end()) {
     if (absl::GetFlag(FLAGS_fail_on_unimplemented_builtin)) {
diff --git a/kythe/cxx/indexer/cxx/KytheGraphObserver.h b/kythe/cxx/indexer/cxx/KytheGraphObserver.h
index c6cdb6156..c0f3a4475 100644
--- a/kythe/cxx/indexer/cxx/KytheGraphObserver.h
+++ b/kythe/cxx/indexer/cxx/KytheGraphObserver.h
@@ -174,8 +174,7 @@ class KytheGraphObserver : public GraphObserver {
     hash_recorder_ = options.hash_recorder;
   }
 
-  NodeId getNodeIdForBuiltinType(
-      const llvm::StringRef& spelling) const override;
+  NodeId getNodeIdForBuiltinType(llvm::StringRef spelling) const override;
 
   const KytheClaimToken* getDefaultClaimToken() const override {
     return &default_token_;
@@ -228,8 +227,7 @@ class KytheGraphObserver : public GraphObserver {
       const NodeId& node,
       const absl::optional<MarkedSource>& marked_source) override;
 
-  void recordLookupNode(const NodeId& node,
-                        const llvm::StringRef& text) override;
+  void recordLookupNode(const NodeId& node, llvm::StringRef text) override;
 
   void recordParamEdge(const NodeId& param_of_id, uint32_t ordinal,
                        const NodeId& param_id) override;
@@ -288,7 +286,7 @@ class KytheGraphObserver : public GraphObserver {
       const absl::optional<MarkedSource>& marked_source) override;
 
   void recordUserDefinedNode(
-      const NodeId& node, const llvm::StringRef& node_kind,
+      const NodeId& node, llvm::StringRef node_kind,
       absl::optional<Completeness> completeness) override;
 
   void recordFullDefinitionRange(
@@ -380,8 +378,7 @@ class KytheGraphObserver : public GraphObserver {
   void recordVisibility(const NodeId& FieldNodeId,
                         clang::AccessSpecifier access) override;
 
-  void recordDeprecated(const NodeId& NodeId,
-                        const llvm::StringRef& advice) override;
+  void recordDeprecated(const NodeId& NodeId, llvm::StringRef advice) override;
 
   void recordDiagnostic(const Range& Range, llvm::StringRef Signature,
                         llvm::StringRef Message) override;
diff --git a/kythe/cxx/indexer/cxx/KytheVFS.cc b/kythe/cxx/indexer/cxx/KytheVFS.cc
index 0ebbac036..49ef05600 100644
--- a/kythe/cxx/indexer/cxx/KytheVFS.cc
+++ b/kythe/cxx/indexer/cxx/KytheVFS.cc
@@ -98,8 +98,7 @@ llvm::ErrorOr<llvm::vfs::Status> IndexVFS::status(const llvm::Twine& path) {
   return make_error_code(llvm::errc::no_such_file_or_directory);
 }
 
-bool IndexVFS::get_vname(const llvm::StringRef& path,
-                         proto::VName* merge_with) {
+bool IndexVFS::get_vname(llvm::StringRef path, proto::VName* merge_with) {
   if (FileRecord* record =
           FileRecordForPath(path, BehaviorOnMissing::kReturnError, 0)) {
     if (record->status.getType() == llvm::sys::fs::file_type::regular_file &&
diff --git a/kythe/cxx/indexer/cxx/KytheVFS.h b/kythe/cxx/indexer/cxx/KytheVFS.h
index 85337439b..d93083765 100644
--- a/kythe/cxx/indexer/cxx/KytheVFS.h
+++ b/kythe/cxx/indexer/cxx/KytheVFS.h
@@ -75,7 +75,7 @@ class IndexVFS : public llvm::vfs::FileSystem {
   /// \param path The path to look up.
   /// \param merge_with The `VName` to copy the vname onto.
   /// \return true if a match was found; false otherwise.
-  bool get_vname(const llvm::StringRef& path, proto::VName* merge_with);
+  bool get_vname(llvm::StringRef path, proto::VName* merge_with);
 
   /// \brief Returns a string representation of `uid` for error messages.
   std::string get_debug_uid_string(const llvm::sys::fs::UniqueID& uid);


Test patch:
diff --git a/kythe/cxx/extractor/cxx_extractor_test.cc b/kythe/cxx/extractor/cxx_extractor_test.cc
index 35eff2334..ad068ac0a 100644
--- a/kythe/cxx/extractor/cxx_extractor_test.cc
+++ b/kythe/cxx/extractor/cxx_extractor_test.cc
@@ -99,8 +99,7 @@ class CxxExtractorTest : public testing::Test {
   /// \param path Absolute path, beginning with / (or B:\ or \\, etc), to the
   /// file to create.
   /// \param code Code to write at the file named by `path`.
-  void AddAbsoluteSourceFile(const llvm::StringRef& path,
-                             const std::string& code) {
+  void AddAbsoluteSourceFile(llvm::StringRef path, const std::string& code) {
     int write_fd;
     UndoableCreateDirectories(path);
     ASSERT_EQ(0, llvm::sys::fs::remove(path).value());