diff mbox

remove nested functions from elf/dl-deps.c

Message ID CAGQ9bdxGg2zzfCcGOj=MxoEKRqAU1ayLLPr6U1HvCtkHMUvKGg@mail.gmail.com
State New
Headers show

Commit Message

Konstantin Serebryany Sept. 30, 2014, 6:40 p.m. UTC
Hi,

Please review the patch that removes nested functions from elf/dl-deps.c
The patch does not noticeably affect the generated code (the new code is 2
instructions shorter, a few differences in used registers, offsets, etc).
The function is inlined in both cases.

No regressions in 'make check' on x86_64-linux-gnu (Ubuntu 14.04)

2014-09-30  Kostya Serebryany  <konstantin.s.serebryany@gmail.com>

        * elf/dl-deps.c
        (preload): New functions broken out of _dl_map_object_deps.
        (_dl_map_object_deps):  Remove a nested function. Update call sites.

--kcc

Comments

Roland McGrath Oct. 1, 2014, 8:49 p.m. UTC | #1
> +static inline
> +void preload (struct link_map *map, struct list *known, unsigned int *nlist)

The return type goes on the first line.  The function name always starts
its line.

It's general policy not to use the 'inline' keyword for static functions in
a .c file.  Unless there is a strong known reason, just let the compiler
decide about inlining.  (This is a relatively recent policy, so you might
find counterexamples in the code.)

When a function has some parameters that are the "context" and some that
are the specific parameters for the specific call, the style I prefer (and
have used throughout the codebase) is to put all the "context" ones first.

> +{
> +  known[*nlist].done = 0;
> +  known[*nlist].map = map;
> +  known[*nlist].next = &known[*nlist + 1];
> +
> +  ++(*nlist);

Drop superfluous parens.


Thanks,
Roland
diff mbox

Patch

diff --git a/elf/dl-deps.c b/elf/dl-deps.c
index c3b0cfc..c4824d1 100644
--- a/elf/dl-deps.c
+++ b/elf/dl-deps.c
@@ -138,6 +138,19 @@  cannot load auxiliary `%s' because of empty dynamic string token "	      \
 									      \
     __result; })
 
+static inline
+void preload (struct link_map *map, struct list *known, unsigned int *nlist)
+{
+  known[*nlist].done = 0;
+  known[*nlist].map = map;
+  known[*nlist].next = &known[*nlist + 1];
+
+  ++(*nlist);
+  /* We use `l_reserved' as a mark bit to detect objects we have
+     already put in the search list and avoid adding duplicate
+     elements later in the list.  */
+  map->l_reserved = 1;
+}
 
 void
 internal_function
@@ -155,28 +168,15 @@  _dl_map_object_deps (struct link_map *map,
   const char *errstring;
   const char *objname;
 
-  void preload (struct link_map *map)
-    {
-      known[nlist].done = 0;
-      known[nlist].map = map;
-      known[nlist].next = &known[nlist + 1];
-
-      ++nlist;
-      /* We use `l_reserved' as a mark bit to detect objects we have
-	 already put in the search list and avoid adding duplicate
-	 elements later in the list.  */
-      map->l_reserved = 1;
-    }
-
   /* No loaded object so far.  */
   nlist = 0;
 
   /* First load MAP itself.  */
-  preload (map);
+  preload (map, known, &nlist);
 
   /* Add the preloaded items after MAP but before any of its dependencies.  */
   for (i = 0; i < npreloads; ++i)
-    preload (preloads[i]);
+    preload (preloads[i], known, &nlist);
 
   /* Terminate the lists.  */
   known[nlist - 1].next = NULL;