Use a helper available in scripts/include/hash.h.
Showing the changes to scripts (1 of 1 file). Show all
Unified · Split
| @@ -21,6 +21,7 @@ · 20 unmodified lines | ||
| 21 | 21 | #include <stdbool.h> |
| 22 | 22 | #include <errno.h> |
| 23 | 23 | |
| 24 | +#include <hash.h> | |
| 24 | 25 | #include <hashtable.h> |
| 25 | 26 | #include <list.h> |
| 26 | 27 | #include <xalloc.h> |
| @@ -210,19 +211,6 @@ struct symbol { · 183 unmodified lines | ||
| 210 | 211 | |
| 211 | 212 | static HASHTABLE_DEFINE(symbol_hashtable, 1U << 10); |
| 212 | 213 | |
| 213 | −/* This is based on the hash algorithm from gdbm, via tdb */ | |
| 214 | −static inline unsigned int tdb_hash(const char *name) | |
| 215 | −{ | |
| 216 | − unsigned value; /* Used to compute the hash value. */ | |
| 217 | − unsigned i; /* Used to cycle through random values. */ | |
| 218 | − | |
| 219 | − /* Set the initial value from the key size. */ | |
| 220 | − for (value = 0x238F13AF * strlen(name), i = 0; name[i]; i++) | |
| 221 | − value = (value + (((unsigned char *)name)[i] << (i*5 % 24))); | |
| 222 | − | |
| 223 | − return (1103515243 * value + 12345); | |
| 224 | −} | |
| 225 | − | |
| 226 | 214 | /** |
| 227 | 215 | * Allocate a new symbols for use in the hash of exported symbols or |
| 228 | 216 | * the list of unresolved symbols per module |
| @@ -240,7 +228,7 @@ static struct symbol *alloc_symbol(const char *name) · 11 unmodified lines | ||
| 240 | 228 | /* For the hash of exported symbols */ |
| 241 | 229 | static void hash_add_symbol(struct symbol *sym) |
| 242 | 230 | { |
| 243 | − hash_add(symbol_hashtable, &sym->hnode, tdb_hash(sym->name)); | |
| 231 | + hash_add(symbol_hashtable, &sym->hnode, hash_str(sym->name)); | |
| 244 | 232 | } |
| 245 | 233 | |
| 246 | 234 | static void sym_add_unresolved(const char *name, struct module *mod, bool weak) |
| @@ -261,7 +249,7 @@ static struct symbol *sym_find_with_module(const char *name, struct module *mod) · 14 unmodified lines | ||
| 261 | 249 | if (name[0] == '.') |
| 262 | 250 | name++; |
| 263 | 251 | |
| 264 | − hash_for_each_possible(symbol_hashtable, s, hnode, tdb_hash(name)) { | |
| 252 | + hash_for_each_possible(symbol_hashtable, s, hnode, hash_str(name)) { | |
| 265 | 253 | if (strcmp(s->name, name) == 0 && (!mod || s->module == mod)) |
| 266 | 254 | return s; |
| 267 | 255 | } |