2009-09-02 Paolo Bonzini <bonzini@gnu.org>
[deliverable/binutils-gdb.git] / bfd / hash.c
index 5edccac350ab707a5c17ea11dd0ae287d152ccd3..0f9fd7e5e650d3d66b8fe584d96d91587869092d 100644 (file)
@@ -451,24 +451,40 @@ 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;
+      char *new_string;
 
-      new = objalloc_alloc ((struct objalloc *) table->memory, len + 1);
-      if (!new)
+      new_string = (char *) objalloc_alloc ((struct objalloc *) table->memory,
+                                            len + 1);
+      if (!new_string)
        {
          bfd_set_error (bfd_error_no_memory);
          return NULL;
        }
-      memcpy (new, string, len + 1);
-      string = new;
+      memcpy (new_string, string, len + 1);
+      string = new_string;
     }
+
+  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 +506,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 +518,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;
This page took 0.053078 seconds and 4 git commands to generate.