]> Cypherpunks repositories - gostls13.git/commitdiff
cmd: use built-in clear for maps instead of range+delete
authorKeith Randall <khr@golang.org>
Tue, 3 Sep 2024 20:53:37 +0000 (13:53 -0700)
committerKeith Randall <khr@golang.org>
Tue, 3 Sep 2024 22:29:23 +0000 (22:29 +0000)
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>
src/cmd/compile/internal/inline/inlheur/scoring.go
src/cmd/compile/internal/liveness/mergelocals.go
src/cmd/compile/internal/liveness/plive.go
src/cmd/compile/internal/ssa/deadstore.go
src/cmd/compile/internal/ssa/debug.go
src/cmd/compile/internal/ssa/regalloc.go
src/cmd/compile/internal/ssagen/ssa.go

index 3ef7c9b79af51a4a81eb158eb481fccdf514555f..c49c087a6298fd8e73c820884b9fcda571375a6a 100644 (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
index 86f1e6ddaaabf494137c736a1ceb1881f8800f2c..25c2c4b3d66345b60c679cd55ea565448dbda205 100644 (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
index c5003ddca6b8307d9579e06297d6c13c9136f0aa..6d6b126e4b59153969f74c5e209215ba17467898 100644 (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
 }
index a0d61bad03b2b967bae973bcfe7f014e22925f0a..9f61ef29b9d527aef1200bd20908c81dbdf4227a 100644 (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 {
index ccd403386e05ece9d62f0c681393a46e629f4dc8..91620798ff599f12bd1cf687cf3a18ccf40076e0 100644 (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
index 1fe95fe97818da9b56e20473af341d59349c90c8..08ce0d16a63bba3994874d167fe2b6e344b680b9 100644 (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
index da755f5a762f51a04d56039ecd3bfd5afcd89a3c..9a566732d270427138f646ec39801ffc0dfa263a 100644 (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.