{"thread":{"id":"38625","subject":"[PATCH] for-each-ref: use skip_prefix() to avoid duplicate string comparison","startedAt":"2015-02-21T19:51:28Z","lastAt":"2015-02-21T19:51:28Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"256475","messageId":"54E8E1C0.5050303@web.de","threadId":"38625","inReplyTo":null,"subject":"[PATCH] for-each-ref: use skip_prefix() to avoid duplicate string comparison","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2015-02-21T19:51:28Z","receivedAt":"2015-02-21T19:51:28Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Use skip_prefix() to get the part after \"color:\" (if present) and only\ncompare it with \"reset\" instead of comparing the whole string again.\nThis gets rid of the duplicate \"color:\" part of the string constant.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n builtin/for-each-ref.c | 7 +++----\n 1 file changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c\nindex 19be78a..83f9cf9 100644\n--- a/builtin/for-each-ref.c\n+++ b/builtin/for-each-ref.c\n@@ -178,11 +178,10 @@ static const char *find_next(const char *cp)\n static int verify_format(const char *format)\n {\n \tconst char *cp, *sp;\n-\tstatic const char color_reset[] = \"color:reset\";\n \n \tneed_color_reset_at_eol = 0;\n \tfor (cp = format; *cp && (sp = find_next(cp)); ) {\n-\t\tconst char *ep = strchr(sp, ')');\n+\t\tconst char *color, *ep = strchr(sp, ')');\n \t\tint at;\n \n \t\tif (!ep)\n@@ -191,8 +190,8 @@ static int verify_format(const char *format)\n \t\tat = parse_atom(sp + 2, ep);\n \t\tcp = ep + 1;\n \n-\t\tif (starts_with(used_atom[at], \"color:\"))\n-\t\t\tneed_color_reset_at_eol = !!strcmp(used_atom[at], color_reset);\n+\t\tif (skip_prefix(used_atom[at], \"color:\", &color))\n+\t\t\tneed_color_reset_at_eol = !!strcmp(color, \"reset\");\n \t}\n \treturn 0;\n }\n-- \n2.3.0\n"}]}