parse_config_key: use skip_prefix instead of starts_with
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>
Jeff King committed
Feb 24, 2017 at 16:07 UTC
e3394fdce79411fd51e20082c0faf7061007bc1c
1 file changed
+3
-4
config.c
+3
-4
@@ -2531,11 +2531,10 @@ int parse_config_key(const char *var,
2531
const char **subsection, int *subsection_len,
2532
const char **key)
2533
{
2534
- int section_len = strlen(section);
2534
const char *dot;
2535
2536
/* Does it start with "section." ? */
2538
- if (!starts_with(var, section) || var[section_len] != '.')
2537
+ if (!skip_prefix(var, section, &var) || *var != '.')
2538
return -1;
2539
2540
/*
@@ -2547,12 +2546,12 @@ int parse_config_key(const char *var,
2546
*key = dot + 1;
2547
2548
/* Did we have a subsection at all? */
2550
- if (dot == var + section_len) {
2549
+ if (dot == var) {
2550
*subsection = NULL;
2551
*subsection_len = 0;
2552
}
2553
else {
2555
- *subsection = var + section_len + 1;
2554
+ *subsection = var + 1;
2555
*subsection_len = dot - *subsection;
2556
}
2557