This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: dynamically resize section merging hash tables.


On Tue, Sep 18, 2007 at 03:41:53PM -0700, Doug Kwan wrote:
> This patch resizes the section merging hash tables at run-time.

I like this, but I think we can better split out the hash table
resizing code as follows.

	* 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.

Index: bfd/bfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in.h,v
retrieving revision 1.128
diff -u -p -r1.128 bfd-in.h
--- bfd/bfd-in.h	12 Jul 2007 07:16:40 -0000	1.128
+++ bfd/bfd-in.h	19 Sep 2007 09:20:24 -0000
@@ -464,6 +464,10 @@ extern struct bfd_hash_entry *bfd_hash_l
   (struct bfd_hash_table *, const char *, bfd_boolean create,
    bfd_boolean copy);
 
+/* Insert an entry in a hash table.  */
+extern struct bfd_hash_entry *bfd_hash_insert
+  (struct bfd_hash_table *, const char *, unsigned long);
+
 /* Replace an entry in a hash table.  */
 extern void bfd_hash_replace
   (struct bfd_hash_table *, struct bfd_hash_entry *old,
Index: bfd/hash.c
===================================================================
RCS file: /cvs/src/src/bfd/hash.c,v
retrieving revision 1.26
diff -u -p -r1.26 hash.c
--- bfd/hash.c	3 Jul 2007 14:26:42 -0000	1.26
+++ bfd/hash.c	19 Sep 2007 09:20:25 -0000
@@ -451,9 +451,6 @@ bfd_hash_lookup (struct bfd_hash_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 *
       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 *
 
       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 *
 	  {
 	    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;
Index: bfd/merge.c
===================================================================
RCS file: /cvs/src/src/bfd/merge.c,v
retrieving revision 1.32
diff -u -p -r1.32 merge.c
--- bfd/merge.c	3 Jul 2007 14:26:42 -0000	1.32
+++ bfd/merge.c	19 Sep 2007 09:20:25 -0000
@@ -220,16 +220,11 @@ sec_merge_hash_lookup (struct sec_merge_
     return NULL;
 
   hashp = ((struct sec_merge_hash_entry *)
-	   sec_merge_hash_newfunc (NULL, &table->table, string));
+	   bfd_hash_insert (&table->table, string, hash));
   if (hashp == NULL)
     return NULL;
-  hashp->root.string = string;
-  hashp->root.hash = hash;
   hashp->len = len;
   hashp->alignment = alignment;
-  hashp->root.next = table->table.table[index];
-  table->table.table[index] = (struct bfd_hash_entry *) hashp;
-
   return hashp;
 }
 

-- 
Alan Modra
Australia Development Lab, IBM


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]