Skip to content

Commit

Permalink
Make llvm::djbHash an inline function.
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D43644

llvm-svn: 326625
  • Loading branch information
rui314 committed Mar 2, 2018
1 parent cbf060f commit e403c86
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
6 changes: 5 additions & 1 deletion llvm/include/llvm/Support/DJB.h
Expand Up @@ -19,7 +19,11 @@
namespace llvm {

/// The Bernstein hash function used by the DWARF accelerator tables.
uint32_t djbHash(StringRef Buffer, uint32_t H = 5381);
inline uint32_t djbHash(StringRef Buffer, uint32_t H = 5381) {
for (unsigned char C : Buffer.bytes())
H = (H << 5) + H + C;
return H;
}

/// Computes the Bernstein hash after folding the input according to the Dwarf 5
/// standard case folding rules.
Expand Down
12 changes: 1 addition & 11 deletions llvm/lib/Support/DJB.cpp
Expand Up @@ -19,16 +19,6 @@

using namespace llvm;

static inline uint32_t djbHashChar(unsigned char C, uint32_t H) {
return (H << 5) + H + C;
}

uint32_t llvm::djbHash(StringRef Buffer, uint32_t H) {
for (unsigned char C : Buffer.bytes())
H = djbHashChar(C, H);
return H;
}

static UTF32 chopOneUTF32(StringRef &Buffer) {
UTF32 C;
const UTF8 *const Begin8Const =
Expand Down Expand Up @@ -86,7 +76,7 @@ uint32_t llvm::caseFoldingDjbHash(StringRef Buffer, uint32_t H) {
// This is by far the most common case, so handle this specially.
if (C >= 'A' && C <= 'Z')
C = 'a' + (C - 'A'); // fold uppercase into lowercase
H = djbHashChar(C, H);
H = (H << 5) + H + C;
Buffer = Buffer.drop_front();
continue;
}
Expand Down

0 comments on commit e403c86

Please sign in to comment.