{"thread":{"id":"44199","subject":"[PATCH] ref-filter: strip format option after a field name only once while parsing","startedAt":"2016-10-02T16:36:35Z","lastAt":"2016-10-02T16:36:35Z","messageCount":1,"participants":["SZEDER Gábor"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"303065","messageId":"20161002163511.609-1-szeder@ira.uka.de","threadId":"44199","inReplyTo":null,"subject":"[PATCH] ref-filter: strip format option after a field name only once while parsing","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2016-10-02T16:35:11Z","receivedAt":"2016-10-02T16:36:35Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"When parse_ref_filter_atom() iterates over a list of valid atoms to\ncheck that a field name is one of them, it has to strip the optional\ncolon-separated format option suffix that might follow the field name.\nHowever, it does so inside the loop, i.e. it performs the exact same\nstripping over and over again.\n\nMove stripping the format option suffix out of that loop, so it's only\nperformed once for each parsed field name.\n\nSigned-off-by: SZEDER Gábor <szeder@ira.uka.de>\n---\n ref-filter.c | 22 +++++++++++-----------\n 1 file changed, 11 insertions(+), 11 deletions(-)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 9adbb8af3eaa..9a8f55e45a16 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -235,7 +235,7 @@ int parse_ref_filter_atom(const char *atom, const char *ep)\n {\n \tconst char *sp;\n \tconst char *arg;\n-\tint i, at;\n+\tint i, at, atom_len;\n \n \tsp = atom;\n \tif (*sp == '*' && sp < ep)\n@@ -250,19 +250,19 @@ int parse_ref_filter_atom(const char *atom, const char *ep)\n \t\t\treturn i;\n \t}\n \n+\t/*\n+\t * If the atom name has a colon, strip it and everything after\n+\t * it off - it specifies the format for this entry, and\n+\t * shouldn't be used for checking against the valid_atom\n+\t * table.\n+\t */\n+\targ = memchr(sp, ':', ep - sp);\n+\tatom_len = (arg ? arg : ep) - sp;\n+\n \t/* Is the atom a valid one? */\n \tfor (i = 0; i < ARRAY_SIZE(valid_atom); i++) {\n \t\tint len = strlen(valid_atom[i].name);\n-\n-\t\t/*\n-\t\t * If the atom name has a colon, strip it and everything after\n-\t\t * it off - it specifies the format for this entry, and\n-\t\t * shouldn't be used for checking against the valid_atom\n-\t\t * table.\n-\t\t */\n-\t\targ = memchr(sp, ':', ep - sp);\n-\t\tif (len == (arg ? arg : ep) - sp &&\n-\t\t    !memcmp(valid_atom[i].name, sp, len))\n+\t\tif (len == atom_len && !memcmp(valid_atom[i].name, sp, len))\n \t\t\tbreak;\n \t}\n \n-- \n2.10.0.516.gccda3a9\n\n"}]}