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 <szeder@ira.uka.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
SZEDER Gábor committed
Oct 2, 2016 at 18:35 UTC
e94ce1394e17e1b91b943b8d41131b6aadb96b88
1 file changed
+11
-11
ref-filter.c
+11
-11
@@ -235,7 +235,7 @@ int parse_ref_filter_atom(const char *atom, const char *ep)
235
{
236
const char *sp;
237
const char *arg;
238
- int i, at;
238
+ int i, at, atom_len;
239
240
sp = atom;
241
if (*sp == '*' && sp < ep)
@@ -250,19 +250,19 @@ int parse_ref_filter_atom(const char *atom, const char *ep)
250
return i;
251
}
252
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
+
262
/* Is the atom a valid one? */
263
for (i = 0; i < ARRAY_SIZE(valid_atom); i++) {
264
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))
266
break;
267
}
268