Skip to content

Commit 51d517b

Browse files
committed
Merge branch 'sg/ref-filter-parse-optim'
The code that parses the format parameter of for-each-ref command has seen a micro-optimization. * sg/ref-filter-parse-optim: ref-filter: strip format option after a field name only once while parsing
2 parents f0798e6 + e94ce13 commit 51d517b

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)