diff options
Diffstat (limited to 'scripts/kconfig/util.c')
-rw-r--r-- | scripts/kconfig/util.c | 93 |
1 files changed, 30 insertions, 63 deletions
diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index b78f114ad48c..5cdcee144b58 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -7,25 +7,42 @@ #include <stdarg.h> #include <stdlib.h> #include <string.h> + +#include <hash.h> +#include <hashtable.h> +#include <xalloc.h> #include "lkc.h" +/* hash table of all parsed Kconfig files */ +static HASHTABLE_DEFINE(file_hashtable, 1U << 11); + +struct file { + struct hlist_node node; + char name[]; +}; + /* file already present in list? If not add it */ -struct file *file_lookup(const char *name) +const char *file_lookup(const char *name) { struct file *file; + size_t len; + int hash = hash_str(name); - for (file = file_list; file; file = file->next) { - if (!strcmp(name, file->name)) { - return file; - } - } + hash_for_each_possible(file_hashtable, file, node, hash) + if (!strcmp(name, file->name)) + return file->name; - file = xmalloc(sizeof(*file)); + len = strlen(name); + file = xmalloc(sizeof(*file) + len + 1); memset(file, 0, sizeof(*file)); - file->name = xstrdup(name); - file->next = file_list; - file_list = file; - return file; + memcpy(file->name, name, len); + file->name[len] = '\0'; + + hash_add(file_hashtable, &file->node, hash); + + str_printf(&autoconf_cmd, "\t%s \\\n", name); + + return file->name; } /* Allocate initial growable string */ @@ -42,8 +59,7 @@ struct gstr str_new(void) /* Free storage for growable string */ void str_free(struct gstr *gs) { - if (gs->s) - free(gs->s); + free(gs->s); gs->s = NULL; gs->len = 0; } @@ -74,56 +90,7 @@ void str_printf(struct gstr *gs, const char *fmt, ...) } /* Retrieve value of growable string */ -char *str_get(struct gstr *gs) +char *str_get(const struct gstr *gs) { return gs->s; } - -void *xmalloc(size_t size) -{ - void *p = malloc(size); - if (p) - return p; - fprintf(stderr, "Out of memory.\n"); - exit(1); -} - -void *xcalloc(size_t nmemb, size_t size) -{ - void *p = calloc(nmemb, size); - if (p) - return p; - fprintf(stderr, "Out of memory.\n"); - exit(1); -} - -void *xrealloc(void *p, size_t size) -{ - p = realloc(p, size); - if (p) - return p; - fprintf(stderr, "Out of memory.\n"); - exit(1); -} - -char *xstrdup(const char *s) -{ - char *p; - - p = strdup(s); - if (p) - return p; - fprintf(stderr, "Out of memory.\n"); - exit(1); -} - -char *xstrndup(const char *s, size_t n) -{ - char *p; - - p = strndup(s, n); - if (p) - return p; - fprintf(stderr, "Out of memory.\n"); - exit(1); -} |