[lld] r326091 - Re-land: "[Support] Replace HashString with djbHash."

Jonas Devlieghere via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 26 07:16:43 PST 2018


Author: jdevlieghere
Date: Mon Feb 26 07:16:42 2018
New Revision: 326091

URL: http://llvm.org/viewvc/llvm-project?rev=326091&view=rev
Log:
Re-land: "[Support] Replace HashString with djbHash."

This patch removes the HashString function from StringExtraces and
replaces its uses with calls to djbHash from DJB.h.

This change is *almost* NFC. While the algorithm is identical, the
djbHash implementation in StringExtras used 0 as its default seed while
the implementation in DJB uses 5381. The latter has been shown to result
in less collisions and improved avalanching and is used by the DWARF
accelerator tables.

Because some test were implicitly relying on the hash order, I've
reverted to using zero as a seed for the following two files:

  lld/include/lld/Core/SymbolTable.h
  llvm/lib/Support/StringMap.cpp

Differential revision: https://reviews.llvm.org/D43615

Modified:
    lld/trunk/include/lld/Core/SymbolTable.h

Modified: lld/trunk/include/lld/Core/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/SymbolTable.h?rev=326091&r1=326090&r2=326091&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/SymbolTable.h (original)
+++ lld/trunk/include/lld/Core/SymbolTable.h Mon Feb 26 07:16:42 2018
@@ -12,7 +12,7 @@
 
 #include "lld/Common/LLVM.h"
 #include "llvm/ADT/DenseSet.h"
-#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/DJB.h"
 #include <cstring>
 #include <map>
 #include <vector>
@@ -65,7 +65,7 @@ private:
     static StringRef getEmptyKey() { return StringRef(); }
     static StringRef getTombstoneKey() { return StringRef(" ", 1); }
     static unsigned getHashValue(StringRef const val) {
-      return llvm::HashString(val);
+      return llvm::djbHash(val, 0);
     }
     static bool isEqual(StringRef const lhs, StringRef const rhs) {
       return lhs.equals(rhs);




More information about the llvm-commits mailing list