Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scripts: move hash function from scripts/kconfig/ to scripts/include/

This function was originally added by commit 8af27e1dc4e4 ("fixdep: use
hash table instead of a single array").

Move it to scripts/include/ so that other host programs can use it.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

+20 -14
+15
scripts/include/hash.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + #ifndef HASH_H 3 + #define HASH_H 4 + 5 + static inline unsigned int hash_str(const char *s) 6 + { 7 + /* fnv32 hash */ 8 + unsigned int hash = 2166136261U; 9 + 10 + for (; *s; s++) 11 + hash = (hash ^ *s) * 0x01000193; 12 + return hash; 13 + } 14 + 15 + #endif /* HASH_H */
-1
scripts/kconfig/lkc.h
··· 51 51 } 52 52 53 53 /* util.c */ 54 - unsigned int strhash(const char *s); 55 54 const char *file_lookup(const char *name); 56 55 57 56 /* lexer.l */
+3 -2
scripts/kconfig/symbol.c
··· 9 9 #include <string.h> 10 10 #include <regex.h> 11 11 12 + #include <hash.h> 12 13 #include <xalloc.h> 13 14 #include "internal.h" 14 15 #include "lkc.h" ··· 894 893 case 'n': return &symbol_no; 895 894 } 896 895 } 897 - hash = strhash(name); 896 + hash = hash_str(name); 898 897 899 898 hash_for_each_possible(sym_hashtable, symbol, node, hash) { 900 899 if (symbol->name && ··· 937 936 case 'n': return &symbol_no; 938 937 } 939 938 } 940 - hash = strhash(name); 939 + hash = hash_str(name); 941 940 942 941 hash_for_each_possible(sym_hashtable, symbol, node, hash) { 943 942 if (symbol->name &&
+2 -11
scripts/kconfig/util.c
··· 8 8 #include <stdlib.h> 9 9 #include <string.h> 10 10 11 + #include <hash.h> 11 12 #include <hashtable.h> 12 13 #include <xalloc.h> 13 14 #include "lkc.h" 14 - 15 - unsigned int strhash(const char *s) 16 - { 17 - /* fnv32 hash */ 18 - unsigned int hash = 2166136261U; 19 - 20 - for (; *s; s++) 21 - hash = (hash ^ *s) * 0x01000193; 22 - return hash; 23 - } 24 15 25 16 /* hash table of all parsed Kconfig files */ 26 17 static HASHTABLE_DEFINE(file_hashtable, 1U << 11); ··· 26 35 { 27 36 struct file *file; 28 37 size_t len; 29 - int hash = strhash(name); 38 + int hash = hash_str(name); 30 39 31 40 hash_for_each_possible(file_hashtable, file, node, hash) 32 41 if (!strcmp(name, file->name))