aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcui <cuiweixie@gmail.com>2021-01-11 08:44:45 +0000
committerEmmanuel Odeke <emmanuel@orijtech.com>2021-03-13 18:09:48 +0000
commit4bd4dfe96a0e7cd252ff0d53ba46618b54618d15 (patch)
treeeb8b466a926523146cdb714a783b6509301eebef /src
parent8336c311f848cb9adc76aeb8bd8172f67bda67e6 (diff)
downloadgo-4bd4dfe96a0e7cd252ff0d53ba46618b54618d15.tar.xz
cmd/compile/internal/ssa: prealloc slice
Change-Id: I9943a4f931c251a69bc8244c0d7723a0a3552073 GitHub-Last-Rev: d9dd94ae4444cb0106756cdb98c1c5fa12fa5f79 GitHub-Pull-Request: golang/go#43622 Reviewed-on: https://go-review.googlesource.com/c/go/+/282992 Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/ssa/lca.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/ssa/lca.go b/src/cmd/compile/internal/ssa/lca.go
index 5cb73911df..90daebe44f 100644
--- a/src/cmd/compile/internal/ssa/lca.go
+++ b/src/cmd/compile/internal/ssa/lca.go
@@ -4,6 +4,10 @@
package ssa
+import (
+ "math/bits"
+)
+
// Code to compute lowest common ancestors in the dominator tree.
// https://en.wikipedia.org/wiki/Lowest_common_ancestor
// https://en.wikipedia.org/wiki/Range_minimum_query#Solution_using_constant_time_and_linearithmic_space
@@ -79,7 +83,7 @@ func makeLCArange(f *Func) *lcaRange {
}
// Compute fast range-minimum query data structure
- var rangeMin [][]ID
+ rangeMin := make([][]ID, 0, bits.Len64(uint64(len(tour))))
rangeMin = append(rangeMin, tour) // 1-size windows are just the tour itself.
for logS, s := 1, 2; s < len(tour); logS, s = logS+1, s*2 {
r := make([]ID, len(tour)-s+1)