@@ -113,7 +113,7 @@ struct item {
113113};
114114
115115#define HASHSZ 256
116- static struct item * hashtab [HASHSZ ];
116+ static struct item * config_hashtab [HASHSZ ];
117117
118118static unsigned int strhash (const char * str , unsigned int sz )
119119{
@@ -125,25 +125,11 @@ static unsigned int strhash(const char *str, unsigned int sz)
125125 return hash ;
126126}
127127
128- /*
129- * Lookup a value in the configuration string.
130- */
131- static int is_defined_config (const char * name , int len , unsigned int hash )
132- {
133- struct item * aux ;
134-
135- for (aux = hashtab [hash % HASHSZ ]; aux ; aux = aux -> next ) {
136- if (aux -> hash == hash && aux -> len == len &&
137- memcmp (aux -> name , name , len ) == 0 )
138- return 1 ;
139- }
140- return 0 ;
141- }
142-
143128/*
144129 * Add a new value to the configuration string.
145130 */
146- static void define_config (const char * name , int len , unsigned int hash )
131+ static void add_to_hashtable (const char * name , int len , unsigned int hash ,
132+ struct item * hashtab [])
147133{
148134 struct item * aux = malloc (sizeof (* aux ) + len );
149135
@@ -158,17 +144,34 @@ static void define_config(const char *name, int len, unsigned int hash)
158144 hashtab [hash % HASHSZ ] = aux ;
159145}
160146
147+ /*
148+ * Lookup a string in the hash table. If found, just return true.
149+ * If not, add it to the hashtable and return false.
150+ */
151+ static bool in_hashtable (const char * name , int len , struct item * hashtab [])
152+ {
153+ struct item * aux ;
154+ unsigned int hash = strhash (name , len );
155+
156+ for (aux = hashtab [hash % HASHSZ ]; aux ; aux = aux -> next ) {
157+ if (aux -> hash == hash && aux -> len == len &&
158+ memcmp (aux -> name , name , len ) == 0 )
159+ return true;
160+ }
161+
162+ add_to_hashtable (name , len , hash , hashtab );
163+
164+ return false;
165+ }
166+
161167/*
162168 * Record the use of a CONFIG_* word.
163169 */
164170static void use_config (const char * m , int slen )
165171{
166- unsigned int hash = strhash (m , slen );
167-
168- if (is_defined_config (m , slen , hash ))
169- return ;
172+ if (in_hashtable (m , slen , config_hashtab ))
173+ return ;
170174
171- define_config (m , slen , hash );
172175 /* Print out a dependency path from a symbol name. */
173176 printf (" $(wildcard include/config/%.*s) \\\n" , slen , m );
174177}
0 commit comments