]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/ssa: prealloc slice
authorcui <cuiweixie@gmail.com>
Mon, 11 Jan 2021 08:44:45 +0000 (08:44 +0000)
committerEmmanuel Odeke <emmanuel@orijtech.com>
Sat, 13 Mar 2021 18:09:48 +0000 (18:09 +0000)
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>

src/cmd/compile/internal/ssa/lca.go

index 5cb73911dfa5e400b8e119ad453532e066d1a173..90daebe44f7141099c76d2d6ebb26e0795b0a0e8 100644 (file)
@@ -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)