[Rpm-maint] [PATCH 1/5] Optimize argvCount function

Alexey Tourbin alexey.tourbin at gmail.com
Tue Feb 5 04:31:35 UTC 2013


Callgrind annotations for 'rpmspec -P anaconda.spec', previous commit:
380,151,860  PROGRAM TOTALS
232,943,797  glibc-2.16-75f0d304/string/../sysdeps/x86_64/strlen.S:__GI_strlen
 63,770,642  rpmio/argv.c:argvCount
 13,702,038  build/parseSpec.c:readLine
...

Callgrind annotations for 'rpmspec -P anaconda.spec', this commit:
364,226,458  PROGRAM TOTALS
232,943,797  glibc-2.16-75f0d304/string/../sysdeps/x86_64/strlen.S:__GI_strlen
 47,845,240  rpmio/argv.c:argvCount
 13,702,038  build/parseSpec.c:readLine
...
---
 rpmio/argv.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/rpmio/argv.c b/rpmio/argv.c
index f061f03..d68422b 100644
--- a/rpmio/argv.c
+++ b/rpmio/argv.c
@@ -69,11 +69,11 @@ ARGint_t argiData(ARGI_const_t argi)
 
 int argvCount(ARGV_const_t argv)
 {
-    int argc = 0;
+    ARGV_const_t argv_start = argv;
     if (argv)
-    while (argv[argc] != NULL)
-	argc++;
-    return argc;
+    while (*argv != NULL)
+	argv++;
+    return argv - argv_start;
 }
 
 ARGV_t argvData(ARGV_t argv)
-- 
1.8.1



More information about the Rpm-maint mailing list