diff options
author | SZEDER Gábor <szeder@ira.uka.de> | 2016-10-02 18:35:11 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-10-03 12:47:19 -0700 |
commit | e94ce1394e17e1b91b943b8d41131b6aadb96b88 (patch) | |
tree | 3da28b721871bc4b5e985c87cf4a26e2ffca9750 | |
parent | 92d426662b0673adcd41995e6c2f0afcb9ad39af (diff) | |
download | git-e94ce1394e17e1b91b943b8d41131b6aadb96b88.tar.gz |
ref-filter: strip format option after a field name only once while parsingsg/ref-filter-parse-optim
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 <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | ref-filter.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/ref-filter.c b/ref-filter.c index 9adbb8af3e..9a8f55e45a 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -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) @@ -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; } |