aboutsummaryrefslogtreecommitdiff
path: root/bfd/hash.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2007-09-19 12:08:34 +0000
committerAlan Modra <amodra@gmail.com>2007-09-19 12:08:34 +0000
commita69898aad0d92d44881d16b6d5d835c3af53b9c1 (patch)
tree9d84644dcc2c6a865c3d475b1193ee1020a013a1 /bfd/hash.c
parent4dcdce139ffe08fec50cd24e688c3e0e21d545c1 (diff)
downloadgdb-a69898aad0d92d44881d16b6d5d835c3af53b9c1.zip
gdb-a69898aad0d92d44881d16b6d5d835c3af53b9c1.tar.gz
gdb-a69898aad0d92d44881d16b6d5d835c3af53b9c1.tar.bz2
* bfd-in.h (bfd_hash_insert): Declare.
* bfd-in2.h: Regenerate. * hash.c (bfd_hash_insert): New function. Split out from.. (bfd_hash_lookup): ..here. * merge.c (sec_merge_hash_lookup): Use bfd_hash_insert.
Diffstat (limited to 'bfd/hash.c')
-rw-r--r--bfd/hash.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/bfd/hash.c b/bfd/hash.c
index 5edccac..14fc403 100644
--- a/bfd/hash.c
+++ b/bfd/hash.c
@@ -451,9 +451,6 @@ bfd_hash_lookup (struct bfd_hash_table *table,
if (! create)
return NULL;
- hashp = (*table->newfunc) (NULL, table, string);
- if (hashp == NULL)
- return NULL;
if (copy)
{
char *new;
@@ -467,8 +464,26 @@ bfd_hash_lookup (struct bfd_hash_table *table,
memcpy (new, string, len + 1);
string = new;
}
+
+ return bfd_hash_insert (table, string, hash);
+}
+
+/* Insert an entry in a hash table. */
+
+struct bfd_hash_entry *
+bfd_hash_insert (struct bfd_hash_table *table,
+ const char *string,
+ unsigned long hash)
+{
+ struct bfd_hash_entry *hashp;
+ unsigned int index;
+
+ hashp = (*table->newfunc) (NULL, table, string);
+ if (hashp == NULL)
+ return NULL;
hashp->string = string;
hashp->hash = hash;
+ index = hash % table->size;
hashp->next = table->table[index];
table->table[index] = hashp;
table->count++;
@@ -490,6 +505,11 @@ bfd_hash_lookup (struct bfd_hash_table *table,
newtable = ((struct bfd_hash_entry **)
objalloc_alloc ((struct objalloc *) table->memory, alloc));
+ if (newtable == NULL)
+ {
+ table->frozen = 1;
+ return hashp;
+ }
memset ((PTR) newtable, 0, alloc);
for (hi = 0; hi < table->size; hi ++)
@@ -497,7 +517,6 @@ bfd_hash_lookup (struct bfd_hash_table *table,
{
struct bfd_hash_entry *chain = table->table[hi];
struct bfd_hash_entry *chain_end = chain;
- int index;
while (chain_end->next && chain_end->next->hash == chain->hash)
chain_end = chain_end->next;