This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils 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: Speedup dwfl_module_addrsym


On Mon, 2011-10-31 at 15:30 -0700, Roland McGrath wrote:
> Rather than the goto, move the matching loop into a nested function that
> takes the loop bounds as arguments.  Then just call that twice.

That does look nicer than the trusty old goto construct. Pushed with
that change (diff -b attached, actual diff was lots of indentation
changes).

Thanks,

Mark
diff --git a/libdwfl/dwfl_module_addrsym.c b/libdwfl/dwfl_module_addrsym.c
index eda1457..9ced0cf 100644
--- a/libdwfl/dwfl_module_addrsym.c
+++ b/libdwfl/dwfl_module_addrsym.c
@@ -104,15 +104,9 @@ dwfl_module_addrsym (Dwfl_Module *mod, GElf_Addr addr,
   /* Keep track of the lowest address a relevant sizeless symbol could have.  */
   GElf_Addr min_label = 0;
 
-  /* First go through global symbols.  mod->first_global is setup by
-     dwfl_module_getsymtab to the index of the first global symbol in
-     the module's symbol table, or -1 when unknown.  All symbols with
-     local binding come first in the symbol table, then all globals.  */
-  int start = mod->first_global < 0 ? 1 : mod->first_global;
-  int end = syments;
-
   /* Look through the symbol table for a matching symbol.  */
-  search_table:
+  inline void search_table (int start, int end)
+    {
   for (int i = start; i < end; ++i)
     {
       GElf_Sym sym;
@@ -175,16 +169,19 @@ dwfl_module_addrsym (Dwfl_Module *mod, GElf_Addr addr,
 	    }
 	}
     }
+    }
+
+  /* First go through global symbols.  mod->first_global is setup by
+     dwfl_module_getsymtab to the index of the first global symbol in
+     the module's symbol table, or -1 when unknown.  All symbols with
+     local binding come first in the symbol table, then all globals.  */
+  search_table (mod->first_global < 0 ? 1 : mod->first_global, syments);
 
   /* If we found nothing searching the global symbols, then try the locals.
      Unless we have a global sizeless symbol that matches exactly.  */
-  if (closest_name == NULL && start != 1 && mod->first_global > 1
+  if (closest_name == NULL && mod->first_global > 1
       && (sizeless_name == NULL || sizeless_sym.st_value != addr))
-    {
-      start = 1;
-      end = mod->first_global;
-      goto search_table;
-    }
+    search_table (1, mod->first_global);
 
   /* If we found no proper sized symbol to use, fall back to the best
      candidate sizeless symbol we found, if any.  */

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