[PATCH] D102484: Avoid calculating the string hash twice in GsymCreator::insertString.

Simon Giesecke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 14 05:16:04 PDT 2021


simon.giesecke created this revision.
simon.giesecke added a reviewer: clayborg.
simon.giesecke added a project: debug-info.
Herald added a subscriber: hiraditya.
simon.giesecke requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102484

Files:
  llvm/lib/DebugInfo/GSYM/GsymCreator.cpp


Index: llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
===================================================================
--- llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
+++ llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
@@ -294,6 +294,7 @@
   if (S.empty())
     return 0;
   std::lock_guard<std::recursive_mutex> Guard(Mutex);
+  CachedHashStringRef CHStr(S);
   if (Copy) {
     // We need to provide backing storage for the string if requested
     // since StringTableBuilder stores references to strings. Any string
@@ -301,11 +302,11 @@
     // copied, but any string created by code will need to be copied.
     // This allows GsymCreator to be really fast when parsing DWARF and
     // other object files as most strings don't need to be copied.
-    CachedHashStringRef CHStr(S);
     if (!StrTab.contains(CHStr))
-      S = StringStorage.insert(S).first->getKey();
+      CHStr = CachedHashStringRef{StringStorage.insert(S).first->getKey(),
+                                  CHStr.hash()};
   }
-  return StrTab.add(S);
+  return StrTab.add(CHStr);
 }
 
 void GsymCreator::addFunctionInfo(FunctionInfo &&FI) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102484.345404.patch
Type: text/x-patch
Size: 1105 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210514/80ad0c48/attachment.bin>


More information about the llvm-commits mailing list