Skip to content

Commit 008d5d0

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2ae7f90 commit 008d5d0

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

builtin/for-each-ref.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,10 @@ static const char *find_next(const char *cp)
180180
static int verify_format(const char *format)
181181
{
182182
const char *cp, *sp;
183-
static const char color_reset[] = "color:reset";
184183

185184
need_color_reset_at_eol = 0;
186185
for (cp = format; *cp && (sp = find_next(cp)); ) {
187-
const char *ep = strchr(sp, ')');
186+
const char *color, *ep = strchr(sp, ')');
188187
int at;
189188

190189
if (!ep)
@@ -193,8 +192,8 @@ static int verify_format(const char *format)
193192
at = parse_atom(sp + 2, ep);
194193
cp = ep + 1;
195194

196-
if (starts_with(used_atom[at], "color:"))
197-
need_color_reset_at_eol = !!strcmp(used_atom[at], color_reset);
195+
if (skip_prefix(used_atom[at], "color:", &color))
196+
need_color_reset_at_eol = !!strcmp(color, "reset");
198197
}
199198
return 0;
200199
}

0 commit comments

Comments
 (0)