From: Doug Evans Date: Mon, 16 Jul 2012 03:07:01 +0000 (+0000) Subject: * symtab.c (filename_seen_cache): Delete members "tab_alloc_size", X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2908cac625ad01a06f4193761a1b4d2f3779b923;p=binutils-gdb.git * symtab.c (filename_seen_cache): Delete members "tab_alloc_size", "tab_cur_size". Change member "tab" to be a htab_t. (create_filename_seen_cache): Update. (clear_filename_seen_cache, delete_filename_seen_cache): Update. (filename_seen): Update. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 5e964448097..6640010ecfb 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2012-07-15 Doug Evans + + * symtab.c (filename_seen_cache): Delete members "tab_alloc_size", + "tab_cur_size". Change member "tab" to be a htab_t. + (create_filename_seen_cache): Update. + (clear_filename_seen_cache, delete_filename_seen_cache): Update. + (filename_seen): Update. + 2012-07-13 Doug Evans * symtab.c (filename_seen): Update comment. diff --git a/gdb/symtab.c b/gdb/symtab.c index d116e576636..183e1157124 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -3108,14 +3108,9 @@ operator_chars (char *p, char **end) struct filename_seen_cache { /* Table of files seen so far. */ - const char **tab; - - /* Allocated size of tab in elements. */ - int tab_alloc_size; + htab_t tab; + /* Initial size of the table. It automagically grows from here. */ #define INITIAL_FILENAME_SEEN_CACHE_SIZE 100 - - /* Current size of tab in elements. */ - int tab_cur_size; }; /* filename_seen_cache constructor. */ @@ -3126,9 +3121,9 @@ create_filename_seen_cache (void) struct filename_seen_cache *cache; cache = XNEW (struct filename_seen_cache); - cache->tab_alloc_size = INITIAL_FILENAME_SEEN_CACHE_SIZE; - cache->tab = XNEWVEC (const char *, cache->tab_alloc_size); - cache->tab_cur_size = 0; + cache->tab = htab_create_alloc (INITIAL_FILENAME_SEEN_CACHE_SIZE, + filename_hash, filename_eq, + NULL, xcalloc, xfree); return cache; } @@ -3136,9 +3131,9 @@ create_filename_seen_cache (void) /* Empty the cache, but do not delete it. */ static void -clear_filename_seen_cache (struct filename_seen_cache * cache) +clear_filename_seen_cache (struct filename_seen_cache *cache) { - cache->tab_cur_size = 0; + htab_empty (cache->tab); } /* filename_seen_cache destructor. @@ -3149,35 +3144,30 @@ delete_filename_seen_cache (void *ptr) { struct filename_seen_cache *cache = ptr; - xfree (cache->tab); + htab_delete (cache->tab); xfree (cache); } /* If FILE is not already in the table of files in CACHE, return zero; otherwise return non-zero. Optionally add FILE to the table if ADD - is non-zero. */ + is non-zero. + + NOTE: We don't manage space for FILE, we assume FILE lives as long + as the caller needs. */ static int filename_seen (struct filename_seen_cache *cache, const char *file, int add) { - const char **p; + void **slot; /* Is FILE in tab? */ - for (p = cache->tab; p < cache->tab + cache->tab_cur_size; p++) - if (filename_cmp (*p, file) == 0) - return 1; + slot = htab_find_slot (cache->tab, file, add ? INSERT : NO_INSERT); + if (*slot != NULL) + return 1; /* No; maybe add it to tab. */ if (add) - { - if (cache->tab_cur_size == cache->tab_alloc_size) - { - cache->tab_alloc_size *= 2; - cache->tab = XRESIZEVEC (const char *, cache->tab, - cache->tab_alloc_size); - } - cache->tab[cache->tab_cur_size++] = file; - } + *slot = (char *) file; return 0; }