]> Cypherpunks repositories - gostls13.git/commitdiff
cmd: make use of maps.{Copy, Clone}
authorJes Cok <xigua67damn@gmail.com>
Fri, 13 Sep 2024 13:48:33 +0000 (13:48 +0000)
committerGopher Robot <gobot@golang.org>
Fri, 13 Sep 2024 21:05:31 +0000 (21:05 +0000)
Change-Id: I8a38b4c71c34d3544ee32be9c6e767bb1099a720
GitHub-Last-Rev: ff4cb4e91be3936465635f99d061f02999640ed9
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>
src/cmd/cgo/main.go
src/cmd/compile/internal/pgoir/irgraph.go
src/cmd/fix/typecheck.go
src/cmd/go/internal/load/godebug.go
src/cmd/go/internal/load/test.go

index 7a78cd270d49df310dddba75ef5203dd93f0d9ce..44252d9144855616f2a54b5dd2f4478d80a35503 100644 (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...)
index 044c18da65001bf8593104be8207fd81341e8216..914a4da8b5c9f29676803d4ba663f8535b855e93 100644 (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
index b115987390cb5221f482ee8a6e22f1a92aeb6ab1..be21582fce3c9071225b352b17a7a6482f7458e2 100644 (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{}}
index 4bb734ce64a808daa82c66938fd15f8d8b5669d1..301090670cce92757a24c7f0d674401df0c9e495 100644 (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
        }
 
index 0a9ddeede15ccc21ab00749ca7d0858a19e9ffb4..31fe23a61c135c9a9864b5b30fcc98168d1fcbce 100644 (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