From 01af72705255fbb48ea3ff3558766537dd0a8ee0 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 19 Mar 2015 23:38:24 +0000 Subject: [PATCH] Revert "cmd/internal/gc: add internConcat for alloc-free string concatenation" This reverts commit 42fcc6fea03673eeed1447eaab78a7df9385246e. Change-Id: If860b7cbff5b5d288c1df1405c1765275dfba7cb Reviewed-on: https://go-review.googlesource.com/7860 Reviewed-by: Russ Cox --- src/cmd/internal/gc/lex.go | 9 --------- src/cmd/internal/gc/lex_test.go | 22 ---------------------- src/cmd/internal/gc/subr.go | 6 +++--- src/cmd/internal/gc/walk.go | 19 +++++++++---------- 4 files changed, 12 insertions(+), 44 deletions(-) delete mode 100644 src/cmd/internal/gc/lex_test.go diff --git a/src/cmd/internal/gc/lex.go b/src/cmd/internal/gc/lex.go index 623c9a1d93e..7470a1ff3a1 100644 --- a/src/cmd/internal/gc/lex.go +++ b/src/cmd/internal/gc/lex.go @@ -1511,15 +1511,6 @@ func internString(b []byte) string { return s } -func internConcat(ss ...string) string { - const bufsiz = 128 // big enough for most compiler uses; must be constant to avoid heap alloc - b := make([]byte, 0, bufsiz) - for _, s := range ss { - b = append(b, s...) - } - return internString(b) -} - func more(pp *string) bool { p := *pp for p != "" && yy_isspace(int(p[0])) { diff --git a/src/cmd/internal/gc/lex_test.go b/src/cmd/internal/gc/lex_test.go deleted file mode 100644 index 845a9d8c36e..00000000000 --- a/src/cmd/internal/gc/lex_test.go +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2015 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package gc - -import "testing" - -func TestInternConcat(t *testing.T) { - fromKind := "T" - toKind := "E" - var s string - n := testing.AllocsPerRun(100, func() { - s = internConcat("conv", fromKind, "2", toKind) - }) - if s != "convT2E" { - t.Fatalf("internConcat(\"conv\", \"T\", \"2\", \"E\")=%q want %q", s, "convT2E") - } - if n > 0 { - t.Errorf("internConcat allocs per run=%f", n) - } -} diff --git a/src/cmd/internal/gc/subr.go b/src/cmd/internal/gc/subr.go index 43aa382206b..32486c77bb8 100644 --- a/src/cmd/internal/gc/subr.go +++ b/src/cmd/internal/gc/subr.go @@ -3574,10 +3574,10 @@ func isdirectiface(t *Type) bool { return false } -// IET returns "T" if t is a concrete type, "I" if t is an interface type, and -// "E" if t is an empty interface type. +// type2IET returns "T" if t is a concrete type, +// "I" if t is an interface type, and "E" if t is an empty interface type. // It is used to build calls to the conv* and assert* runtime routines. -func (t *Type) IET() string { +func type2IET(t *Type) string { if isnilinter(t) { return "E" } diff --git a/src/cmd/internal/gc/walk.go b/src/cmd/internal/gc/walk.go index 591974d18b2..2784648a858 100644 --- a/src/cmd/internal/gc/walk.go +++ b/src/cmd/internal/gc/walk.go @@ -678,7 +678,7 @@ func walkexpr(np **Node, init **NodeList) { n1 := Nod(OADDR, n.Left, nil) r := n.Right // i.(T) - buf := internConcat("assert", r.Left.Type.IET(), "2", r.Type.IET()) + buf := "assert" + type2IET(r.Left.Type) + "2" + type2IET(r.Type) fn := syslook(buf, 1) substArgTypes(fn, r.Left.Type, r.Type) @@ -869,8 +869,8 @@ func walkexpr(np **Node, init **NodeList) { oktype = ok.Type } - fromKind := from.Type.IET() - toKind := t.IET() + fromKind := type2IET(from.Type) + toKind := type2IET(t) // Avoid runtime calls in a few cases of the form _, ok := i.(T). // This is faster and shorter and allows the corresponding assertX2X2 @@ -903,7 +903,7 @@ func walkexpr(np **Node, init **NodeList) { } resptr.Etype = 1 // addr does not escape - buf := internConcat("assert", fromKind, "2", toKind, "2") + buf := "assert" + fromKind + "2" + toKind + "2" fn := syslook(buf, 1) substArgTypes(fn, from.Type, t) call := mkcall1(fn, oktype, init, typename(t), from, resptr) @@ -927,7 +927,11 @@ func walkexpr(np **Node, init **NodeList) { goto ret } - // Handle fast paths and special cases. + // Build name of function: convI2E etc. + // Not all names are possible + // (e.g., we'll never generate convE2E or convE2I). + buf := "conv" + type2IET(n.Left.Type) + "2" + type2IET(n.Type) + fn := syslook(buf, 1) var ll *NodeList if !Isinter(n.Left.Type) { ll = list(ll, typename(n.Left.Type)) @@ -1006,11 +1010,6 @@ func walkexpr(np **Node, init **NodeList) { } } - // Build name of function: convI2E etc. - // Not all names are possible - // (e.g., we'll never generate convE2E or convE2I). - buf := internConcat("conv", n.Left.Type.IET(), "2", n.Type.IET()) - fn := syslook(buf, 1) substArgTypes(fn, n.Left.Type, n.Type) dowidth(fn.Type) n = Nod(OCALL, fn, nil)