Skip to content

Commit e94ce13

Browse files
szedergitster
authored andcommitted
ref-filter: strip format option after a field name only once while parsing
When parse_ref_filter_atom() iterates over a list of valid atoms to check that a field name is one of them, it has to strip the optional colon-separated format option suffix that might follow the field name. However, it does so inside the loop, i.e. it performs the exact same stripping over and over again. Move stripping the format option suffix out of that loop, so it's only performed once for each parsed field name. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 92d4266 commit e94ce13

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

ref-filter.c

+11-11
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ int parse_ref_filter_atom(const char *atom, const char *ep)
235235
{
236236
const char *sp;
237237
const char *arg;
238-
int i, at;
238+
int i, at, atom_len;
239239

240240
sp = atom;
241241
if (*sp == '*' && sp < ep)
@@ -250,19 +250,19 @@ int parse_ref_filter_atom(const char *atom, const char *ep)
250250
return i;
251251
}
252252

253+
/*
254+
* If the atom name has a colon, strip it and everything after
255+
* it off - it specifies the format for this entry, and
256+
* shouldn't be used for checking against the valid_atom
257+
* table.
258+
*/
259+
arg = memchr(sp, ':', ep - sp);
260+
atom_len = (arg ? arg : ep) - sp;
261+
253262
/* Is the atom a valid one? */
254263
for (i = 0; i < ARRAY_SIZE(valid_atom); i++) {
255264
int len = strlen(valid_atom[i].name);
256-
257-
/*
258-
* If the atom name has a colon, strip it and everything after
259-
* it off - it specifies the format for this entry, and
260-
* shouldn't be used for checking against the valid_atom
261-
* table.
262-
*/
263-
arg = memchr(sp, ':', ep - sp);
264-
if (len == (arg ? arg : ep) - sp &&
265-
!memcmp(valid_atom[i].name, sp, len))
265+
if (len == atom_len && !memcmp(valid_atom[i].name, sp, len))
266266
break;
267267
}
268268

0 commit comments

Comments
 (0)