Skip to content

Commit a16219b

Browse files
committed
scripts: move hash function from scripts/kconfig/ to scripts/include/
This function was originally added by commit 8af27e1 ("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 <[email protected]>
1 parent 9a41821 commit a16219b

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

scripts/include/hash.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 */

scripts/kconfig/lkc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ static inline void xfwrite(const void *str, size_t len, size_t count, FILE *out)
5151
}
5252

5353
/* util.c */
54-
unsigned int strhash(const char *s);
5554
const char *file_lookup(const char *name);
5655

5756
/* lexer.l */

scripts/kconfig/symbol.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <string.h>
1010
#include <regex.h>
1111

12+
#include <hash.h>
1213
#include <xalloc.h>
1314
#include "internal.h"
1415
#include "lkc.h"
@@ -893,7 +894,7 @@ struct symbol *sym_lookup(const char *name, int flags)
893894
case 'n': return &symbol_no;
894895
}
895896
}
896-
hash = strhash(name);
897+
hash = hash_str(name);
897898

898899
hash_for_each_possible(sym_hashtable, symbol, node, hash) {
899900
if (symbol->name &&
@@ -936,7 +937,7 @@ struct symbol *sym_find(const char *name)
936937
case 'n': return &symbol_no;
937938
}
938939
}
939-
hash = strhash(name);
940+
hash = hash_str(name);
940941

941942
hash_for_each_possible(sym_hashtable, symbol, node, hash) {
942943
if (symbol->name &&

scripts/kconfig/util.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,11 @@
88
#include <stdlib.h>
99
#include <string.h>
1010

11+
#include <hash.h>
1112
#include <hashtable.h>
1213
#include <xalloc.h>
1314
#include "lkc.h"
1415

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-
2516
/* hash table of all parsed Kconfig files */
2617
static HASHTABLE_DEFINE(file_hashtable, 1U << 11);
2718

@@ -35,7 +26,7 @@ const char *file_lookup(const char *name)
3526
{
3627
struct file *file;
3728
size_t len;
38-
int hash = strhash(name);
29+
int hash = hash_str(name);
3930

4031
hash_for_each_possible(file_hashtable, file, node, hash)
4132
if (!strcmp(name, file->name))

0 commit comments

Comments
 (0)