[PATCH 1/3] parse_config_key: use skip_prefix instead of starts_with
- From
Jeff King <peff@peff.net>
- Date
- Feb 24, 2017, 21:07 UTC
- Message-ID
- <20170224210719.zyf5bd6dtwhi5s3f@sigill.intra.peff.net>
- In-Reply-To
- <20170224210643.max6z2ykm3gbg7lw@sigill.intra.peff.net>
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> --- config.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/config.c b/config.c index c6b874a7b..1b08a75a7 100644 --- a/config.c +++ b/config.c @@ -2536,11 +2536,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; /* @@ -2552,12 +2551,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; }
-- 2.12.0.616.g5f622f3b1