1
0
mirror of https://github.com/golang/go synced 2024-11-22 08:54:39 -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" "go/token"
"internal/buildcfg" "internal/buildcfg"
"io" "io"
"maps"
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
@ -598,12 +599,8 @@ func (p *Package) Record(f *File) {
} }
// merge nocallback & noescape // merge nocallback & noescape
for k, v := range f.NoCallbacks { maps.Copy(p.noCallbacks, f.NoCallbacks)
p.noCallbacks[k] = v maps.Copy(p.noEscapes, f.NoEscapes)
}
for k, v := range f.NoEscapes {
p.noEscapes[k] = v
}
if f.ExpFunc != nil { if f.ExpFunc != nil {
p.ExpFunc = append(p.ExpFunc, f.ExpFunc...) p.ExpFunc = append(p.ExpFunc, f.ExpFunc...)

View File

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

View File

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

View File

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

View File

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