1
0
mirror of https://github.com/golang/go synced 2024-11-25 08:57:58 -07:00

cmd: use built-in clear for maps instead of range+delete

Now that we're bootstrapping from a toolchain that has the clear builtin.

Update #64751

Change-Id: Ia86d96c253c9f7c66131cd02048a493047569641
Reviewed-on: https://go-review.googlesource.com/c/go/+/610237
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
Keith Randall 2024-09-03 13:53:37 -07:00
parent f90f7e90b3
commit 0c16278124
7 changed files with 12 additions and 39 deletions

View File

@ -569,9 +569,7 @@ func ScoreCallsCleanup() {
allCallSites[call] = cs
}
}
for k := range scoreCallsCache.tab {
delete(scoreCallsCache.tab, k)
}
clear(scoreCallsCache.tab)
}
// GetCallSiteScore returns the previously calculated score for call

View File

@ -489,8 +489,8 @@ func (cs *cstate) populateIndirectUseTable(cands []*ir.Name) ([]*ir.Name, []cand
rawcands[n] = struct{}{}
}
for k := 0; k < len(cs.f.Blocks); k++ {
genmapclear(pendingUses)
genmapclear(blockIndirectUE)
clear(pendingUses)
clear(blockIndirectUE)
b := cs.f.Blocks[k]
for _, v := range b.Values {
if n, e := affectedVar(v); n != nil {
@ -546,7 +546,7 @@ func (cs *cstate) populateIndirectUseTable(cands []*ir.Name) ([]*ir.Name, []cand
// that value is flowing out of the block off somewhere else,
// we're going to treat that local as truly address-taken and
// not have it be a merge candidate.
genmapclear(evicted)
clear(evicted)
if len(pendingUses) != 0 {
for id, nc := range pendingUses {
if cs.trace > 2 {
@ -605,14 +605,6 @@ func (cs *cstate) populateIndirectUseTable(cands []*ir.Name) ([]*ir.Name, []cand
return pruned, regions
}
// FIXME: bootstrap tool compiler is build with a "go 1.20" go.mod, so
// we are not allowed to use map clear yet. Use this helper instead.
func genmapclear[KT comparable, VT any](m map[KT]VT) {
for k := range m {
delete(m, k)
}
}
type nameCount struct {
n *ir.Name
count int32

View File

@ -168,15 +168,9 @@ func (m *Map) reset() {
m.UnsafeVals = make(map[ssa.ID]bool)
m.UnsafeBlocks = make(map[ssa.ID]bool)
} else {
for k := range m.Vals {
delete(m.Vals, k)
}
for k := range m.UnsafeVals {
delete(m.UnsafeVals, k)
}
for k := range m.UnsafeBlocks {
delete(m.UnsafeBlocks, k)
}
clear(m.Vals)
clear(m.UnsafeVals)
clear(m.UnsafeBlocks)
}
m.DeferReturn = objw.StackMapDontCare
}

View File

@ -29,10 +29,7 @@ func dse(f *Func) {
// storeUse contains stores which are used by a subsequent store.
loadUse.clear()
storeUse.clear()
// TODO(deparker): use the 'clear' builtin once compiler bootstrap minimum version is raised to 1.21.
for k := range localAddrs {
delete(localAddrs, k)
}
clear(localAddrs)
stores = stores[:0]
for _, v := range b.Values {
if v.Op == OpPhi {

View File

@ -588,9 +588,7 @@ func BuildFuncDebug(ctxt *obj.Link, f *Func, loggingLevel int, stackOffset func(
if state.varParts == nil {
state.varParts = make(map[*ir.Name][]SlotID)
} else {
for n := range state.varParts {
delete(state.varParts, n)
}
clear(state.varParts)
}
// Recompose any decomposed variables, and establish the canonical

View File

@ -2228,13 +2228,9 @@ func (e *edgeState) setup(idx int, srcReg []endReg, dstReg []startReg, stacklive
}
// Clear state.
for _, vid := range e.cachedVals {
delete(e.cache, vid)
}
clear(e.cache)
e.cachedVals = e.cachedVals[:0]
for k := range e.contents {
delete(e.contents, k)
}
clear(e.contents)
e.usedRegs = 0
e.uniqueRegs = 0
e.finalRegs = 0

View File

@ -991,9 +991,7 @@ func (s *state) startBlock(b *ssa.Block) {
}
s.curBlock = b
s.vars = map[ir.Node]*ssa.Value{}
for n := range s.fwdVars {
delete(s.fwdVars, n)
}
clear(s.fwdVars)
}
// endBlock marks the end of generating code for the current block.