aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/ssa/sparseset.go
diff options
context:
space:
mode:
authorDavid Chase <drchase@google.com>2016-05-09 14:59:25 -0400
committerRuss Cox <rsc@golang.org>2016-05-18 14:05:14 +0000
commitd35a4158ab66aef99d9204c65cc2e2fa74b57a73 (patch)
tree3ee31a60d1d975a0cdf82f2474fa81673733d193 /src/cmd/compile/internal/ssa/sparseset.go
parent2380a039c0457141e28f8f927139e1f9c38f8205 (diff)
downloadgo-d35a4158ab66aef99d9204c65cc2e2fa74b57a73.tar.gz
go-d35a4158ab66aef99d9204c65cc2e2fa74b57a73.zip
cmd/compile: reduce element size of arrays in sparse{map,set}
sparseSet and sparseMap only need 32 bit integers in their arrays, since a sparseEntry key is also limited to 32 bits. This appears to reduce the space allocated for at least one pathological compilation by 1%, perhaps more. Not necessarily for 1.7, but it saves a little and is very low-risk. Change-Id: Icf1185859e9f5fe1261a206b441e02c34f7d02fd Reviewed-on: https://go-review.googlesource.com/22972 Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/ssa/sparseset.go')
-rw-r--r--src/cmd/compile/internal/ssa/sparseset.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/cmd/compile/internal/ssa/sparseset.go b/src/cmd/compile/internal/ssa/sparseset.go
index 66bebf139e..b5cabfb0cd 100644
--- a/src/cmd/compile/internal/ssa/sparseset.go
+++ b/src/cmd/compile/internal/ssa/sparseset.go
@@ -9,13 +9,13 @@ package ssa
type sparseSet struct {
dense []ID
- sparse []int
+ sparse []int32
}
// newSparseSet returns a sparseSet that can represent
// integers between 0 and n-1
func newSparseSet(n int) *sparseSet {
- return &sparseSet{nil, make([]int, n)}
+ return &sparseSet{dense: nil, sparse: make([]int32, n)}
}
func (s *sparseSet) cap() int {
@@ -28,16 +28,16 @@ func (s *sparseSet) size() int {
func (s *sparseSet) contains(x ID) bool {
i := s.sparse[x]
- return i < len(s.dense) && s.dense[i] == x
+ return i < int32(len(s.dense)) && s.dense[i] == x
}
func (s *sparseSet) add(x ID) {
i := s.sparse[x]
- if i < len(s.dense) && s.dense[i] == x {
+ if i < int32(len(s.dense)) && s.dense[i] == x {
return
}
s.dense = append(s.dense, x)
- s.sparse[x] = len(s.dense) - 1
+ s.sparse[x] = int32(len(s.dense)) - 1
}
func (s *sparseSet) addAll(a []ID) {
@@ -54,7 +54,7 @@ func (s *sparseSet) addAllValues(a []*Value) {
func (s *sparseSet) remove(x ID) {
i := s.sparse[x]
- if i < len(s.dense) && s.dense[i] == x {
+ if i < int32(len(s.dense)) && s.dense[i] == x {
y := s.dense[len(s.dense)-1]
s.dense[i] = y
s.sparse[y] = i