Optimize string tag length calculations in regionSwab()
authorPanu Matilainen <pmatilai@redhat.com>
Tue, 29 Nov 2011 08:05:44 +0000 (10:05 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Tue, 29 Nov 2011 08:38:53 +0000 (10:38 +0200)
- Calling memchr() is circa 35% faster on my system than doing the
  same manually, and this in one of the most critical paths rpm has...

lib/header.c

index c3ecc87..a9f3f25 100644 (file)
@@ -300,11 +300,13 @@ unsigned headerSizeof(Header h, int magicp)
 /* Bounded header string (array) size calculation, return -1 on error */
 static inline int strtaglen(const char *str, rpm_count_t c, const char *end)
 {
+    const char *start = str;
     const char *s;
 
-    for (s = str; s < end; s++) {
-       if ((*s == '\0') && (--c == 0))
+    while ((s = memchr(start, '\0', end-start))) {
+       if (--c == 0 || s > end)
            break;
+       start = s + 1;
     }
     return (c > 0) ? -1 : (s - str + 1);
 }