git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] for-each-ref: use skip_prefix() to avoid duplicate string comparison

From
René Scharfe <l.s.r@web.de>
Date
Feb 21, 2015, 19:51 UTC
Message-ID
<54E8E1C0.5050303@web.de>

Use skip_prefix() to get the part after "color:" (if present) and only compare it with "reset" instead of comparing the whole string again. This gets rid of the duplicate "color:" part of the string constant.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 builtin/for-each-ref.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index 19be78a..83f9cf9 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -178,11 +178,10 @@ static const char *find_next(const char *cp)
 static int verify_format(const char *format)
 {
 	const char *cp, *sp;
-	static const char color_reset[] = "color:reset";
 
 	need_color_reset_at_eol = 0;
 	for (cp = format; *cp && (sp = find_next(cp)); ) {
-		const char *ep = strchr(sp, ')');
+		const char *color, *ep = strchr(sp, ')');
 		int at;
 
 		if (!ep)
@@ -191,8 +190,8 @@ static int verify_format(const char *format)
 		at = parse_atom(sp + 2, ep);
 		cp = ep + 1;
 
-		if (starts_with(used_atom[at], "color:"))
-			need_color_reset_at_eol = !!strcmp(used_atom[at], color_reset);
+		if (skip_prefix(used_atom[at], "color:", &color))
+			need_color_reset_at_eol = !!strcmp(color, "reset");
 	}
 	return 0;
 }
-- 
2.3.0
Message 1 of 1 in “for-each-ref: use skip_prefix() to avoid duplicate string comparison”
  1. for-each-ref: use skip_prefix() to avoid duplicate string comparisonRené Scharfe, Feb 21, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.