1
0
mirror of https://github.com/golang/go synced 2024-11-22 03:14:41 -07:00

cmd: make use of maps.{Copy, Clone}

Change-Id: I8a38b4c71c34d3544ee32be9c6e767bb1099a720
GitHub-Last-Rev: ff4cb4e91b
GitHub-Pull-Request: golang/go#69424
Reviewed-on: https://go-review.googlesource.com/c/go/+/612735
Reviewed-by: Keith Randall <khr@golang.org>
Commit-Queue: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
Jes Cok 2024-09-13 13:48:33 +00:00 committed by Gopher Robot
parent 76e44f42c8
commit 0a2cc74f5a
5 changed files with 13 additions and 19 deletions

View File

@ -18,6 +18,7 @@ import (
"go/token"
"internal/buildcfg"
"io"
"maps"
"os"
"path/filepath"
"reflect"
@ -598,12 +599,8 @@ func (p *Package) Record(f *File) {
}
// merge nocallback & noescape
for k, v := range f.NoCallbacks {
p.noCallbacks[k] = v
}
for k, v := range f.NoEscapes {
p.noEscapes[k] = v
}
maps.Copy(p.noCallbacks, f.NoCallbacks)
maps.Copy(p.noEscapes, f.NoEscapes)
if f.ExpFunc != nil {
p.ExpFunc = append(p.ExpFunc, f.ExpFunc...)

View File

@ -50,6 +50,7 @@ import (
"cmd/compile/internal/types"
"cmd/internal/pgo"
"fmt"
"maps"
"os"
)
@ -296,10 +297,7 @@ func addIndirectEdges(g *IRGraph, namedEdgeMap pgo.NamedEdgeMap) {
// package build by VisitIR. We want to filter for local functions
// below, but we also add unknown callees to IRNodes as we go. So make
// an initial copy of IRNodes to recall just the local functions.
localNodes := make(map[string]*IRNode, len(g.IRNodes))
for k, v := range g.IRNodes {
localNodes[k] = v
}
localNodes := maps.Clone(g.IRNodes)
// N.B. We must consider edges in a stable order because export data
// lookup order (LookupMethodFunc, below) can impact the export data of

View File

@ -9,6 +9,7 @@ import (
"go/ast"
"go/parser"
"go/token"
"maps"
"os"
"os/exec"
"path/filepath"
@ -272,9 +273,9 @@ func typecheck(cfg *TypeConfig, f *ast.File) (typeof map[any]string, assign map[
if !copied {
copied = true
// Copy map lazily: it's time.
cfg1.Type = make(map[string]*Type)
for k, v := range cfg.Type {
cfg1.Type[k] = v
cfg1.Type = maps.Clone(cfg.Type)
if cfg1.Type == nil {
cfg1.Type = make(map[string]*Type)
}
}
t := &Type{Field: map[string]string{}}

View File

@ -9,6 +9,7 @@ import (
"fmt"
"go/build"
"internal/godebugs"
"maps"
"sort"
"strconv"
"strings"
@ -89,9 +90,7 @@ func defaultGODEBUG(p *Package, directives, testDirectives, xtestDirectives []bu
defaults := godebugForGoVersion(goVersion)
if defaults != nil {
// Apply m on top of defaults.
for k, v := range m {
defaults[k] = v
}
maps.Copy(defaults, m)
m = defaults
}

View File

@ -15,6 +15,7 @@ import (
"go/parser"
"go/token"
"internal/lazytemplate"
"maps"
"path/filepath"
"slices"
"sort"
@ -212,9 +213,7 @@ func TestPackagesAndErrors(ctx context.Context, done func(), opts PackageOpts, p
if testEmbed == nil && len(p.Internal.Embed) > 0 {
testEmbed = map[string][]string{}
}
for k, v := range p.Internal.Embed {
testEmbed[k] = v
}
maps.Copy(testEmbed, p.Internal.Embed)
ptest.Internal.Embed = testEmbed
ptest.EmbedFiles = str.StringList(p.EmbedFiles, p.TestEmbedFiles)
ptest.Internal.OrigImportPath = p.Internal.OrigImportPath