parse_config_key: use skip_prefix instead of starts_with
authorJeff King <peff@peff.net>
Fri, 24 Feb 2017 21:07:19 +0000 (16:07 -0500)
committerJunio C Hamano <gitster@pobox.com>
Fri, 24 Feb 2017 21:22:09 +0000 (13:22 -0800)
This saves us having to repeatedly add in "section_len" (and
also avoids walking over the first part of the string
multiple times for a strlen() and strrchr()).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
config.c
index 617b2e3cf4a9dcb61283ea797166d2bda812de6f..a23f260792f14be45cc8c50df358b49e9136c671 100644 (file)
--- a/config.c
+++ b/config.c
@@ -2531,11 +2531,10 @@ int parse_config_key(const char *var,
                     const char **subsection, int *subsection_len,
                     const char **key)
 {
-       int section_len = strlen(section);
        const char *dot;
 
        /* Does it start with "section." ? */
-       if (!starts_with(var, section) || var[section_len] != '.')
+       if (!skip_prefix(var, section, &var) || *var != '.')
                return -1;
 
        /*
@@ -2547,12 +2546,12 @@ int parse_config_key(const char *var,
        *key = dot + 1;
 
        /* Did we have a subsection at all? */
-       if (dot == var + section_len) {
+       if (dot == var) {
                *subsection = NULL;
                *subsection_len = 0;
        }
        else {
-               *subsection = var + section_len + 1;
+               *subsection = var + 1;
                *subsection_len = dot - *subsection;
        }