Thread (30 messages) flat view 30 messages, 4 authors, 2016-06-15
STALE3720d

[PATCH 7/9] for-each-ref: prepoplulate all atoms before show_ref()

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 22:57:19
Subsystem: the rest · Maintainer: Linus Torvalds

By the time show_ref() is called, atom values for all refs are
ready. This can be taken advantage of later.

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 builtin/for-each-ref.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index db5c211..a9d189c 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -1010,15 +1010,24 @@ static void show_ref(struct strbuf *sb, struct refinfo *info,
 static void show_refs(struct refinfo **refs, int maxcount,
 		      const char *format, int quote_style)
 {
-	struct strbuf sb = STRBUF_INIT;
+	struct strbuf *sb;
 	int i;
 
+	sb = xmalloc(sizeof(*sb) * maxcount);
 	for (i = 0; i < maxcount; i++) {
-		strbuf_reset(&sb);
-		show_ref(&sb, refs[i], format, quote_style);
-		fputs(sb.buf, stdout);
+		strbuf_init(sb + i, 256);
+		if (!refs[i]->value) {
+			populate_value(refs[i]);
+			fill_missing_values(refs[i]->value);
+		}
+	}
+
+	for (i = 0; i < maxcount; i++) {
+		show_ref(sb + i, refs[i], format, quote_style);
+		fputs(sb[i].buf, stdout);
+		strbuf_release(sb + i);
 	}
-	strbuf_release(&sb);
+	free(sb);
 }
 
 static struct ref_sort *default_sort(void)
-- 
1.8.2.83.gc99314b
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help