Thread (7 messages) flat view 7 messages, 3 authors, 2016-06-15
STALE3732d

[PATCH 3/3] get_urlmatch: avoid useless strbuf write

From: Jeff King <hidden>
Date: 2016-06-15 23:06:14
Subsystem: the rest · Maintainer: Linus Torvalds

We create a strbuf only to insert a single string, pass the
resulting buffer to a function (which does not modify the
string), and then free it. We can just pass the original
string instead.

Signed-off-by: Jeff King <redacted>
---
I keep staring at this thinking I missed something, but I think this is
an equivalent transformation. I wonder if the original meant to modify
the key in some way, but I don't see how or why.

 builtin/config.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/builtin/config.c b/builtin/config.c
index 04befce..71acc44 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -425,14 +425,11 @@ static int get_urlmatch(const char *var, const char *url)
 
 	for_each_string_list_item(item, &values) {
 		struct urlmatch_current_candidate_value *matched = item->util;
-		struct strbuf key = STRBUF_INIT;
 		struct strbuf buf = STRBUF_INIT;
 
-		strbuf_addstr(&key, item->string);
-		format_config(&buf, key.buf,
+		format_config(&buf, item->string,
 			      matched->value_is_null ? NULL : matched->value.buf);
 		fwrite(buf.buf, 1, buf.len, stdout);
-		strbuf_release(&key);
 		strbuf_release(&buf);
 
 		strbuf_release(&matched->value);
-- 
2.5.0.680.g69e7703
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help