PATCH: speed up ar(1)

Mark Kettenis kettenis@gnu.org
Thu Mar 10 21:31:00 GMT 2005


   Date: Tue, 08 Mar 2005 10:44:04 +1100
   From: Ben Elliston <bje@au1.ibm.com>

   The following patch alters the ar cache representation from a
   singly linked list to a hash table using the hashtab implementation
   from libiberty.  When archiving files with thousands of archive
   members (eg. libjava), this patch results in a 15-25% performance
   improvement.

   Tested with an --enable-targets=all build, make check-binutils and
   a byte-wise comparison of the libjava libraries built with and
   without a patched ar.

But with a compiler that's far too modern for your own good ;-).

   Okay to commit?

Not really; this isn't proper ISO C90...

   Index: archive.c
   ===================================================================
   RCS file: /home/bje/src-cvs/src/bfd/archive.c,v
   retrieving revision 1.34
   diff -u -r1.34 archive.c
   --- archive.c	3 Mar 2005 11:40:56 -0000	1.34
   +++ archive.c	7 Mar 2005 22:48:34 -0000
   @@ -247,14 +247,36 @@
     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;

But since it already went in, I committed the attached obvious patch.

Take care,

Mark


Index: ChangeLog
from  Mark Kettenis  <kettenis@gnu.org>

	* archive.c (_bfd_look_for_bfd_in_cache): Move declaration of
	has_table to the start of the function.

Index: archive.c
===================================================================
RCS file: /cvs/src/src/bfd/archive.c,v
retrieving revision 1.35
diff -u -p -r1.35 archive.c
--- archive.c 10 Mar 2005 00:29:35 -0000 1.35
+++ archive.c 10 Mar 2005 21:25:21 -0000
@@ -247,10 +247,10 @@ bfd_set_archive_head (bfd *output_archiv
 bfd *
 _bfd_look_for_bfd_in_cache (bfd *arch_bfd, file_ptr filepos)
 {
+  htab_t hash_table = bfd_ardata (arch_bfd)->cache;
   struct ar_cache m;
   m.ptr = filepos;
 
-  htab_t hash_table = bfd_ardata (arch_bfd)->cache;
   if (hash_table)
     {
       struct ar_cache *entry = (struct ar_cache *) htab_find (hash_table, &m);



More information about the Binutils mailing list