From cfbf375a81a54027bdbd8e74a946d0c1124dc771 Mon Sep 17 00:00:00 2001 From: David Chase Date: Fri, 18 May 2018 17:43:11 -0400 Subject: [PATCH] cmd/compile: common up code in fuse for joining blocks There's semantically-but-not-literally equivalent code in two cases for joining blocks' value lists in ssa/fuse.go. It can be made literally equivalent, then commoned up. Updates #25426. Change-Id: Id1819366c9d22e5126f9203dcd4c622423994110 Reviewed-on: https://go-review.googlesource.com/113719 Run-TryBot: David Chase TryBot-Result: Gobot Gobot Reviewed-by: Josh Bleecher Snyder --- src/cmd/compile/internal/ssa/fuse.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cmd/compile/internal/ssa/fuse.go b/src/cmd/compile/internal/ssa/fuse.go index ca840e37ff..4f9a2ad9ca 100644 --- a/src/cmd/compile/internal/ssa/fuse.go +++ b/src/cmd/compile/internal/ssa/fuse.go @@ -155,21 +155,21 @@ func fuseBlockPlain(b *Block) bool { // debugging information depends on the order of *Values in Blocks. // This can also cause changes in the order (which may affect other // optimizations and possibly compiler output) for 32-vs-64 bit compilation - // platforms (word size affects allocation bucket size affects slice size). + // platforms (word size affects allocation bucket size affects slice capacity). if cap(c.Values) >= cap(b.Values) || len(b.Values) <= len(b.valstorage) { bl := len(b.Values) cl := len(c.Values) + var t []*Value // construct t = b.Values followed-by c.Values, but with attention to allocation. if cap(c.Values) < bl+cl { // reallocate - t := make([]*Value, 0, bl+cl) - t = append(t, b.Values...) - c.Values = append(t, c.Values...) + t = make([]*Value, bl+cl) } else { // in place. - c.Values = c.Values[0 : bl+cl] - copy(c.Values[bl:], c.Values) - copy(c.Values, b.Values) + t = c.Values[0 : bl+cl] } + copy(t[bl:], c.Values) // possibly in-place + c.Values = t + copy(c.Values, b.Values) } else { c.Values = append(b.Values, c.Values...) } -- 2.48.1