From 8744d35dd3429b175559ca89799858b1fd497bcb Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 27 Jun 2012 17:06:49 -0400 Subject: [PATCH] runtime: avoid allocation for "" + x + "" R=golang-dev, r CC=golang-dev https://golang.org/cl/6359043 --- src/pkg/runtime/string.goc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pkg/runtime/string.goc b/src/pkg/runtime/string.goc index 090c4cd20e..8a5d59b81d 100644 --- a/src/pkg/runtime/string.goc +++ b/src/pkg/runtime/string.goc @@ -141,15 +141,22 @@ runtime·catstring(String s1, String s2) static String concatstring(int32 n, String *s) { - int32 i, l; + int32 i, l, count; String out; l = 0; + count = 0; for(i=0; i 0) { + count++; + out = s[i]; + } } + if(count <= 1) // zero or one non-empty string in concatenation + return out; out = gostringsize(l); l = 0; -- 2.50.0