From ffaa48bd2f356e08538ccc6e46043b96cf5c55f8 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Wed, 24 Jan 2018 16:53:14 +0000 Subject: [PATCH] [NFC] Make magic number for DJB hash function customizable. This allows us to specify the magic number for the DJB hash function. This feature is needed by dsymutil to emit Apple types accelerator table. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@323341 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/BinaryFormat/Dwarf.h | 2 +- lib/BinaryFormat/Dwarf.cpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/include/llvm/BinaryFormat/Dwarf.h b/include/llvm/BinaryFormat/Dwarf.h index 6e2b2ce093c..3f2d328b915 100644 --- a/include/llvm/BinaryFormat/Dwarf.h +++ b/include/llvm/BinaryFormat/Dwarf.h @@ -526,7 +526,7 @@ private: enum DwarfFormat : uint8_t { DWARF32, DWARF64 }; /// The Bernstein hash function used by the accelerator tables. -uint32_t djbHash(StringRef Buffer); +uint32_t djbHash(StringRef Buffer, uint32_t H = 5381); } // End of namespace dwarf diff --git a/lib/BinaryFormat/Dwarf.cpp b/lib/BinaryFormat/Dwarf.cpp index 593ce7a1965..74f86a84a98 100644 --- a/lib/BinaryFormat/Dwarf.cpp +++ b/lib/BinaryFormat/Dwarf.cpp @@ -587,8 +587,7 @@ bool llvm::dwarf::isValidFormForVersion(Form F, unsigned Version, return ExtensionsOk; } -uint32_t llvm::dwarf::djbHash(StringRef Buffer) { - uint32_t H = 5381; +uint32_t llvm::dwarf::djbHash(StringRef Buffer, uint32_t H) { for (char C : Buffer.bytes()) H = ((H << 5) + H) + C; return H; -- 2.11.0