Skip to content

Commit

Permalink
Minor symbol lookup improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
Melchizedek6809 committed Dec 3, 2023
1 parent 2d6d5de commit a6f0b28
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/symbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ lSymbol *lSymSM(const char *str){
}

static inline u32 lHashSymStr(const char *str){
return fasthash32(str, strlen(str), 0x8b0a159d);
return fasthash32(str, strlen(str), 0x5b0a159d9eac0381ULL);
}

// Probes the symbol index and returns the slot where STR is stored. If STR is
Expand Down
23 changes: 21 additions & 2 deletions third-party/fasthash/fasthash.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@
(h) *= 0x2127599bf4325c37ULL; \
(h) ^= (h) >> 47; })

/**
* fasthash64v - 64-bit implementation of fasthash
* @v: data to hash
* @seed: the seed
*/
static inline uint64_t fasthash64v(uint64_t v){
const uint64_t m = 0x880355f21e6d1965ULL;
const uint64_t seed = 0x5b0a159d9eac0381ULL;
uint64_t h = seed ^ (8 * m);
h ^= mix(v);
h *= m;
return mix(h);
}

static inline uint32_t fasthash32v(uint64_t v){
const uint64_t h = fasthash64v(v);
return h - (h >> 32);
}

/**
* fasthash64 - 64-bit implementation of fasthash
* @buf: data buffer
Expand Down Expand Up @@ -80,11 +99,11 @@ static inline uint64_t fasthash64(const void *buf, size_t len, uint64_t seed){
* @len: data size
* @seed: the seed
*/
static inline uint32_t fasthash32(const void *buf, size_t len, uint32_t seed){
static inline uint32_t fasthash32(const void *buf, size_t len, uint64_t seed){
// the following trick converts the 64-bit hashcode to Fermat
// residue, which shall retain information from both the higher
// and lower parts of hashcode.
uint64_t h = fasthash64(buf, len, seed);
const uint64_t h = fasthash64(buf, len, seed);
return h - (h >> 32);
}

Expand Down

0 comments on commit a6f0b28

Please sign in to comment.