for-each-ref: use skip_prefix() to avoid duplicate string comparison
Use skip_prefix() to get the part after "color:" (if present) and only compare it with "reset" instead of comparing the whole string again. This gets rid of the duplicate "color:" part of the string constant. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
2ae7f90f26
commit
008d5d005d
@ -180,11 +180,10 @@ static const char *find_next(const char *cp)
|
|||||||
static int verify_format(const char *format)
|
static int verify_format(const char *format)
|
||||||
{
|
{
|
||||||
const char *cp, *sp;
|
const char *cp, *sp;
|
||||||
static const char color_reset[] = "color:reset";
|
|
||||||
|
|
||||||
need_color_reset_at_eol = 0;
|
need_color_reset_at_eol = 0;
|
||||||
for (cp = format; *cp && (sp = find_next(cp)); ) {
|
for (cp = format; *cp && (sp = find_next(cp)); ) {
|
||||||
const char *ep = strchr(sp, ')');
|
const char *color, *ep = strchr(sp, ')');
|
||||||
int at;
|
int at;
|
||||||
|
|
||||||
if (!ep)
|
if (!ep)
|
||||||
@ -193,8 +192,8 @@ static int verify_format(const char *format)
|
|||||||
at = parse_atom(sp + 2, ep);
|
at = parse_atom(sp + 2, ep);
|
||||||
cp = ep + 1;
|
cp = ep + 1;
|
||||||
|
|
||||||
if (starts_with(used_atom[at], "color:"))
|
if (skip_prefix(used_atom[at], "color:", &color))
|
||||||
need_color_reset_at_eol = !!strcmp(used_atom[at], color_reset);
|
need_color_reset_at_eol = !!strcmp(color, "reset");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user