Skip to content

Commit

Permalink
ref-filter: strip format option after a field name only once while pa…
Browse files Browse the repository at this point in the history
…rsing

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]>
  • Loading branch information
szeder authored and gitster committed Oct 3, 2016
1 parent 92d4266 commit e94ce13
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions ref-filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ int parse_ref_filter_atom(const char *atom, const char *ep)
{
const char *sp;
const char *arg;
int i, at;
int i, at, atom_len;

sp = atom;
if (*sp == '*' && sp < ep)
Expand All @@ -250,19 +250,19 @@ int parse_ref_filter_atom(const char *atom, const char *ep)
return i;
}

/*
* If the atom name has a colon, strip it and everything after
* it off - it specifies the format for this entry, and
* shouldn't be used for checking against the valid_atom
* table.
*/
arg = memchr(sp, ':', ep - sp);
atom_len = (arg ? arg : ep) - sp;

/* Is the atom a valid one? */
for (i = 0; i < ARRAY_SIZE(valid_atom); i++) {
int len = strlen(valid_atom[i].name);

/*
* If the atom name has a colon, strip it and everything after
* it off - it specifies the format for this entry, and
* shouldn't be used for checking against the valid_atom
* table.
*/
arg = memchr(sp, ':', ep - sp);
if (len == (arg ? arg : ep) - sp &&
!memcmp(valid_atom[i].name, sp, len))
if (len == atom_len && !memcmp(valid_atom[i].name, sp, len))
break;
}

Expand Down

0 comments on commit e94ce13

Please sign in to comment.