This is the mail archive of the binutils@sources.redhat.com 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: RFC: Short circuit bfd_map_over_sections


On Thu, Apr 29, 2004 at 05:01:33PM -0700, H. J. Lu wrote:
> bfd_map_over_sections is used to call a function on each section in
> a bfd. However, there are many places where bfd_map_over_sections
> is called to find something. It isn't necessary to go through all
> sections once it is found. I'd like to modify bfd_map_over_sections to

I like the idea.  The following trick might help too, allowing you to
find sections with the same name without going via bfd_map_over_sections.

I don't intend to apply this patch unless you (or others) find a use for
it.

Index: bfd/section.c
===================================================================
RCS file: /cvs/src/src/bfd/section.c,v
retrieving revision 1.67
diff -u -p -r1.67 section.c
--- bfd/section.c	1 Dec 2003 06:33:01 -0000	1.67
+++ bfd/section.c	30 Apr 2004 01:26:16 -0000
@@ -945,13 +945,19 @@ bfd_make_section_anyway (bfd *abfd, cons
   newsect = &sh->section;
   if (newsect->name != NULL)
     {
-      /* We are making a section of the same name.  It can't go in
-	 section_htab without generating a unique section name and
-	 that would be pointless;  We don't need to traverse the
-	 hash table.  */
-      newsect = bfd_zalloc (abfd, sizeof (asection));
-      if (newsect == NULL)
+      /* We are making a section of the same name.  Put it in the
+	 section hash table.  Even though we can't find it directly by a
+	 hash lookup, we'll be able to find the section by traversing
+	 sh->root.next quicker than looking at all the bfd sections.  */
+      struct section_hash_entry *new_sh;
+      new_sh = (struct section_hash_entry *)
+	bfd_section_hash_newfunc (NULL, &abfd->section_htab, name);
+      if (new_sh == NULL)
 	return NULL;
+
+      new_sh->root.next = sh->root.next;
+      sh->root.next = &new_sh->root;
+      newsect = &new_sh->section;
     }
 
   newsect->name = name;

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


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