PR 3532
authorAlan Modra <amodra@gmail.com>
Mon, 20 Nov 2006 01:38:38 +0000 (01:38 +0000)
committerAlan Modra <amodra@gmail.com>
Mon, 20 Nov 2006 01:38:38 +0000 (01:38 +0000)
* bfd-in.h (struct bfd_hash_table): Reorganize.  Add "frozen".
* hash.c (bfd_hash_table_init_n): Init frozen.
(bfd_hash_lookup): Don't grow if frozen.
(bfd_hash_traverse): Freeze hash table during traversal.
* bfd-in2.h: Regenerate.

bfd/ChangeLog
bfd/bfd-in.h
bfd/bfd-in2.h
bfd/hash.c

index 50c98532f26cc91a52191f96505c5295accb126a..bbd545991e9ff047b59ccfea3e23533941d5d7df 100644 (file)
@@ -1,3 +1,12 @@
+2006-11-20  Alan Modra  <amodra@bigpond.net.au>
+
+       PR 3532
+       * bfd-in.h (struct bfd_hash_table): Reorganize.  Add "frozen".
+       * hash.c (bfd_hash_table_init_n): Init frozen.
+       (bfd_hash_lookup): Don't grow if frozen.
+       (bfd_hash_traverse): Freeze hash table during traversal.
+       * bfd-in2.h: Regenerate.
+
 2006-11-18  Alan Modra  <amodra@bigpond.net.au>
 
        * elflink.c (_bfd_elf_check_kept_section): Test for kept group
index e671ee7d23e5eb68c796c112be4ca3709d6b52e5..35ce39652923237f54c898230b3ef48e77401bad 100644 (file)
@@ -398,12 +398,6 @@ struct bfd_hash_table
 {
   /* The hash array.  */
   struct bfd_hash_entry **table;
-  /* The number of slots in the hash table.  */
-  unsigned int size;
-  /* The number of entries in the hash table.  */
-  unsigned int count;
-  /* The size of elements.  */
-  unsigned int entsize;
   /* A function used to create new elements in the hash table.  The
      first entry is itself a pointer to an element.  When this
      function is first invoked, this pointer will be NULL.  However,
@@ -416,6 +410,14 @@ struct bfd_hash_table
    /* An objalloc for this hash table.  This is a struct objalloc *,
      but we use void * to avoid requiring the inclusion of objalloc.h.  */
   void *memory;
+  /* The number of slots in the hash table.  */
+  unsigned int size;
+  /* The number of entries in the hash table.  */
+  unsigned int count;
+  /* The size of elements.  */
+  unsigned int entsize;
+  /* If non-zero, don't grow the hash table.  */
+  unsigned int frozen:1;
 };
 
 /* Initialize a hash table.  */
index 8f2af8bc45d56814463198296d58037b7801952b..80eb8a272be1ca207a5262d368050636b80d11fe 100644 (file)
@@ -405,12 +405,6 @@ struct bfd_hash_table
 {
   /* The hash array.  */
   struct bfd_hash_entry **table;
-  /* The number of slots in the hash table.  */
-  unsigned int size;
-  /* The number of entries in the hash table.  */
-  unsigned int count;
-  /* The size of elements.  */
-  unsigned int entsize;
   /* A function used to create new elements in the hash table.  The
      first entry is itself a pointer to an element.  When this
      function is first invoked, this pointer will be NULL.  However,
@@ -423,6 +417,14 @@ struct bfd_hash_table
    /* An objalloc for this hash table.  This is a struct objalloc *,
      but we use void * to avoid requiring the inclusion of objalloc.h.  */
   void *memory;
+  /* The number of slots in the hash table.  */
+  unsigned int size;
+  /* The number of entries in the hash table.  */
+  unsigned int count;
+  /* The size of elements.  */
+  unsigned int entsize;
+  /* If non-zero, don't grow the hash table.  */
+  unsigned int frozen:1;
 };
 
 /* Initialize a hash table.  */
index 3cc4f79644e756fb3ebb99f00b4b0a3e12db679c..1157980a8f8aa06f591cabed7dc270a47574c736 100644 (file)
@@ -383,6 +383,7 @@ bfd_hash_table_init_n (struct bfd_hash_table *table,
   table->size = size;
   table->entsize = entsize;
   table->count = 0;
+  table->frozen = 0;
   table->newfunc = newfunc;
   return TRUE;
 }
@@ -471,7 +472,7 @@ bfd_hash_lookup (struct bfd_hash_table *table,
   table->table[index] = hashp;
   table->count++;
 
-  if (table->count > table->size * 3 / 4)
+  if (!table->frozen && table->count > table->size * 3 / 4)
     {
       unsigned long newsize = higher_prime_number (table->size);
       struct bfd_hash_entry **newtable;
@@ -482,8 +483,7 @@ bfd_hash_lookup (struct bfd_hash_table *table,
         that much memory, don't try to grow the table.  */
       if (newsize == 0 || alloc / sizeof (struct bfd_hash_entry *) != newsize)
        {
-         /* Lie.  Stops us trying to grow again for a while.  */
-         table->count = 0;
+         table->frozen = 1;
          return hashp;
        }
 
@@ -573,14 +573,17 @@ bfd_hash_traverse (struct bfd_hash_table *table,
 {
   unsigned int i;
 
+  table->frozen = 1;
   for (i = 0; i < table->size; i++)
     {
       struct bfd_hash_entry *p;
 
       for (p = table->table[i]; p != NULL; p = p->next)
        if (! (*func) (p, info))
-         return;
+         goto out;
     }
+ out:
+  table->frozen = 0;
 }
 \f
 void
This page took 0.031389 seconds and 4 git commands to generate.