kconfig: avoid multiple calls to strlen
authorYann E. MORIN <yann.morin.1998@free.fr>
Sat, 13 Jul 2013 13:09:43 +0000 (15:09 +0200)
committerChristian Lamparter <chunkeey@googlemail.com>
Wed, 23 Oct 2013 20:21:22 +0000 (22:21 +0200)
Calls to strlen are costly, so avoid calling strln as much as we can.

Reported-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Cc: Jean Delvare <jdelvare@suse.de>
Reviewed-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Christian Lamparter <chunkeey@googlemail.com>
config/symbol.c

index d550300ec00c34e5b1748478c6381341e9412e0b..020a0ac147e103ec65740fbd4b1d4ac20109fd2a 100644 (file)
@@ -967,7 +967,7 @@ static int sym_rel_comp( const void *sym1, const void *sym2 )
 {
        struct sym_match *s1 = *(struct sym_match **)sym1;
        struct sym_match *s2 = *(struct sym_match **)sym2;
-       int l1, l2;
+       int exact1, exact2;
 
        /* Exact match:
         * - if matched length on symbol s1 is the length of that symbol,
@@ -978,11 +978,11 @@ static int sym_rel_comp( const void *sym1, const void *sym2 )
         * exactly; if this is the case, we can't decide which comes first,
         * and we fallback to sorting alphabetically.
         */
-       l1 = s1->eo - s1->so;
-       l2 = s2->eo - s2->so;
-       if (l1 == strlen(s1->sym->name) && l2 != strlen(s2->sym->name))
+       exact1 = (s1->eo - s1->so) == strlen(s1->sym->name);
+       exact2 = (s2->eo - s2->so) == strlen(s2->sym->name);
+       if (exact1 && !exact2)
                return -1;
-       if (l1 != strlen(s1->sym->name) && l2 == strlen(s2->sym->name))
+       if (!exact1 && exact2)
                return 1;
 
        /* As a fallback, sort symbols alphabetically */