]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
* archive.c: Include hashtab.h.
authorBen Elliston <bje@au.ibm.com>
Thu, 10 Mar 2005 00:29:35 +0000 (00:29 +0000)
committerBen Elliston <bje@au.ibm.com>
Thu, 10 Mar 2005 00:29:35 +0000 (00:29 +0000)
(struct ar_cache): Rename `arelt' to `arbfd' and remove `next'.
(_bfd_look_for_bfd_in_cache): Reimplement using htab_find.
(hash_file_ptr): New function.
(eq_file_ptr): Likewise.
(_bfd_add_bfd_to_archive_cache): Reimplement using a hash table.
* libbfd-in.h: Include hashtab.h.
(struct artdata): Change `cache' member type to htab_t.
* libbfd.h: Rebuild.

bfd/ChangeLog
bfd/archive.c
bfd/libbfd-in.h
bfd/libbfd.h

index ec9d85702b20a76099b0cbbb478273be5a4f916d..f394852279cae5c2fef31525cb5a8cdfd788f64c 100644 (file)
@@ -1,3 +1,15 @@
+2005-03-10  Ben Elliston  <bje@au.ibm.com>
+
+       * archive.c: Include hashtab.h.
+       (struct ar_cache): Rename `arelt' to `arbfd' and remove `next'.
+       (_bfd_look_for_bfd_in_cache): Reimplement using htab_find.
+       (hash_file_ptr): New function.
+       (eq_file_ptr): Likewise.
+       (_bfd_add_bfd_to_archive_cache): Reimplement using a hash table.
+       * libbfd-in.h: Include hashtab.h.
+       (struct artdata): Change `cache' member type to htab_t.
+       * libbfd.h: Rebuild.
+
 2005-03-08  Daniel Jacobowitz  <dan@codesourcery.com>
 
        * configure.in: Bump version to 2.16.90.
index f8bf76a8bf38fc18155703ab5a4364defe7545a2..2fedd29acbfe4e2eb4cba1249a041444b39662ec 100644 (file)
@@ -133,6 +133,7 @@ DESCRIPTION
 #include "aout/ar.h"
 #include "aout/ranlib.h"
 #include "safe-ctype.h"
+#include "hashtab.h"
 
 #ifndef errno
 extern int errno;
@@ -146,8 +147,7 @@ extern int errno;
    to the front of the contents!  */
 struct ar_cache {
   file_ptr ptr;
-  bfd *arelt;
-  struct ar_cache *next;
+  bfd *arbfd;
 };
 
 #define ar_padchar(abfd) ((abfd)->xvec->ar_pad_char)
@@ -247,14 +247,36 @@ bfd_set_archive_head (bfd *output_archive, bfd *new_head)
 bfd *
 _bfd_look_for_bfd_in_cache (bfd *arch_bfd, file_ptr filepos)
 {
-  struct ar_cache *current;
+  struct ar_cache m;
+  m.ptr = filepos;
 
-  for (current = bfd_ardata (arch_bfd)->cache; current != NULL;
-       current = current->next)
-    if (current->ptr == filepos)
-      return current->arelt;
+  htab_t hash_table = bfd_ardata (arch_bfd)->cache;
+  if (hash_table)
+    {
+      struct ar_cache *entry = (struct ar_cache *) htab_find (hash_table, &m);
+      if (!entry)
+       return NULL;
+      else
+       return entry->arbfd;
+    }
+  else
+    return NULL;
+}
 
-  return NULL;
+static hashval_t
+hash_file_ptr (const PTR p)
+{
+  return (hashval_t) (((struct ar_cache *) p)->ptr);
+}
+
+/* Returns non-zero if P1 and P2 are equal.  */
+
+static int
+eq_file_ptr (const PTR p1, const PTR p2)
+{
+  struct ar_cache *arc1 = (struct ar_cache *) p1;
+  struct ar_cache *arc2 = (struct ar_cache *) p2;
+  return arc1->ptr == arc2->ptr;
 }
 
 /* Kind of stupid to call cons for each one, but we don't do too many.  */
@@ -262,26 +284,25 @@ _bfd_look_for_bfd_in_cache (bfd *arch_bfd, file_ptr filepos)
 bfd_boolean
 _bfd_add_bfd_to_archive_cache (bfd *arch_bfd, file_ptr filepos, bfd *new_elt)
 {
-  bfd_size_type amt = sizeof (struct ar_cache);
-
-  struct ar_cache *new_cache = bfd_zalloc (arch_bfd, amt);
-  if (new_cache == NULL)
-    return FALSE;
+  struct ar_cache *cache;
+  htab_t hash_table = bfd_ardata (arch_bfd)->cache;
 
-  new_cache->ptr = filepos;
-  new_cache->arelt = new_elt;
-  new_cache->next = NULL;
-  if (bfd_ardata (arch_bfd)->cache == NULL)
-    bfd_ardata (arch_bfd)->cache = new_cache;
-  else
+  /* If the hash table hasn't been created, create it.  */
+  if (hash_table == NULL)
     {
-      struct ar_cache *current = bfd_ardata (arch_bfd)->cache;
-
-      while (current->next != NULL)
-       current = current->next;
-      current->next = new_cache;
+      hash_table = htab_create_alloc (16, hash_file_ptr, eq_file_ptr,
+                                     NULL, calloc, free);
+      if (hash_table == NULL)
+       return FALSE;
+      bfd_ardata (arch_bfd)->cache = hash_table;
     }
 
+  /* Insert new_elt into the hash table by filepos.  */
+  cache = bfd_zalloc (arch_bfd, sizeof (struct ar_cache));
+  cache->ptr = filepos;
+  cache->arbfd = new_elt;
+  *htab_find_slot (hash_table, (const void *) cache, INSERT) = cache;
+
   return TRUE;
 }
 \f
index 396ece3adc1868f46623252217b8adcddcdd2bf3..cc65a56301f29644ceacd29cea7452f012426dd6 100644 (file)
@@ -23,6 +23,8 @@ You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
+#include "hashtab.h"
+
 /* Align an address upward to a boundary, expressed as a number of bytes.
    E.g. align to an 8-byte boundary with argument of 8.  Take care never
    to wrap around if the address is within boundary-1 of the end of the
@@ -57,7 +59,7 @@ struct bfd_in_memory
 struct artdata {
   file_ptr first_file_filepos;
   /* Speed up searching the armap */
-  struct ar_cache *cache;
+  htab_t cache;
   bfd *archive_head;           /* Only interesting in output routines */
   carsym *symdefs;             /* the symdef entries */
   symindex symdef_count;       /* how many there are */
index 8afdf8963567866535b074415bf7b01fca6460bc..ee6b42186f1277fdd059d6203d3dc0aa006f1437 100644 (file)
@@ -28,6 +28,8 @@ You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
+#include "hashtab.h"
+
 /* Align an address upward to a boundary, expressed as a number of bytes.
    E.g. align to an 8-byte boundary with argument of 8.  Take care never
    to wrap around if the address is within boundary-1 of the end of the
@@ -62,7 +64,7 @@ struct bfd_in_memory
 struct artdata {
   file_ptr first_file_filepos;
   /* Speed up searching the armap */
-  struct ar_cache *cache;
+  htab_t cache;
   bfd *archive_head;           /* Only interesting in output routines */
   carsym *symdefs;             /* the symdef entries */
   symindex symdef_count;       /* how many there are */