[PATCH] D69335: [Support] Replace StringRef hashing algorithm with DJB

Ehud Katz via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 23 05:03:29 PDT 2019


ekatz created this revision.
ekatz added reviewers: lattner, JDevlieghere, chandlerc.
ekatz added a project: LLVM.
Herald added subscribers: llvm-commits, hiraditya.

DJB hashing has entered in r326091 (https://reviews.llvm.org/D43615), for performance purposes (as described in the commit message). I am unaware of a reason for not to replace the StringRef's default hashing algorithm with DJB, instead of using it specifically for StringMap. Using StringRef as the Key for DenseMap should have the same performance boost.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69335

Files:
  llvm/lib/Support/StringMap.cpp
  llvm/lib/Support/StringRef.cpp


Index: llvm/lib/Support/StringRef.cpp
===================================================================
--- llvm/lib/Support/StringRef.cpp
+++ llvm/lib/Support/StringRef.cpp
@@ -12,6 +12,7 @@
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/edit_distance.h"
+#include "llvm/Support/DJB.h"
 #include <bitset>
 
 using namespace llvm;
@@ -595,5 +596,5 @@
 
 // Implementation of StringRef hashing.
 hash_code llvm::hash_value(StringRef S) {
-  return hash_combine_range(S.begin(), S.end());
+  return djbHash(S, 0);
 }
Index: llvm/lib/Support/StringMap.cpp
===================================================================
--- llvm/lib/Support/StringMap.cpp
+++ llvm/lib/Support/StringMap.cpp
@@ -13,7 +13,6 @@
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Compiler.h"
-#include "llvm/Support/DJB.h"
 #include "llvm/Support/MathExtras.h"
 #include <cassert>
 
@@ -80,7 +79,7 @@
     init(16);
     HTSize = NumBuckets;
   }
-  unsigned FullHashValue = djbHash(Name, 0);
+  unsigned FullHashValue = hash_value(Name);
   unsigned BucketNo = FullHashValue & (HTSize-1);
   unsigned *HashTable = (unsigned *)(TheTable + NumBuckets + 1);
 
@@ -134,7 +133,7 @@
 int StringMapImpl::FindKey(StringRef Key) const {
   unsigned HTSize = NumBuckets;
   if (HTSize == 0) return -1;  // Really empty table?
-  unsigned FullHashValue = djbHash(Key, 0);
+  unsigned FullHashValue = hash_value(Key);
   unsigned BucketNo = FullHashValue & (HTSize-1);
   unsigned *HashTable = (unsigned *)(TheTable + NumBuckets + 1);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69335.226118.patch
Type: text/x-patch
Size: 1590 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191023/7dd5068d/attachment.bin>


More information about the llvm-commits mailing list