aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorDoug Evans <dje@google.com>2012-07-16 03:07:01 +0000
committerDoug Evans <dje@google.com>2012-07-16 03:07:01 +0000
commit2908cac625ad01a06f4193761a1b4d2f3779b923 (patch)
treeb8fcdff2e4e64884006a6fb63499558d2e0fba56 /gdb
parente51dc8bc2ac536b7f9cb4c4fa79b1f39a8845f57 (diff)
downloadgdb-2908cac625ad01a06f4193761a1b4d2f3779b923.zip
gdb-2908cac625ad01a06f4193761a1b4d2f3779b923.tar.gz
gdb-2908cac625ad01a06f4193761a1b4d2f3779b923.tar.bz2
* 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.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog8
-rw-r--r--gdb/symtab.c44
2 files changed, 25 insertions, 27 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 5e96444..6640010 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@
+2012-07-15 Doug Evans <dje@google.com>
+
+ * 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 <dje@google.com>
* symtab.c (filename_seen): Update comment.
diff --git a/gdb/symtab.c b/gdb/symtab.c
index d116e57..183e115 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;
}