pickaxe: call strlen only when necessary in diffcore_pickaxe_count()
authorRené Scharfe <l.s.r@web.de>
Sat, 22 Mar 2014 17:15:59 +0000 (18:15 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 24 Mar 2014 22:13:17 +0000 (15:13 -0700)
We need to determine the search term's length only when fixed-string
matching is used; regular expression compilation takes a NUL-terminated
string directly. Only call strlen() in the former case.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diffcore-pickaxe.c
index 827a7d7e7625cd9ab8695dbca07924279f3068f2..70753d058a5411e353832600ccb3206f480e9e14 100644 (file)
@@ -205,7 +205,6 @@ void diffcore_pickaxe(struct diff_options *o)
 {
        const char *needle = o->pickaxe;
        int opts = o->pickaxe_opts;
-       unsigned long len = strlen(needle);
        regex_t regex, *regexp = NULL;
        kwset_t kws = NULL;
 
@@ -226,7 +225,7 @@ void diffcore_pickaxe(struct diff_options *o)
        } else {
                kws = kwsalloc(DIFF_OPT_TST(o, PICKAXE_IGNORE_CASE)
                               ? tolower_trans_tbl : NULL);
-               kwsincr(kws, needle, len);
+               kwsincr(kws, needle, strlen(needle));
                kwsprep(kws);
        }