aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/load.go
diff options
context:
space:
mode:
authorDaniel Martí <mvdan@mvdan.cc>2024-03-26 22:59:41 +0200
committerDaniel Martí <mvdan@mvdan.cc>2024-03-27 21:58:12 +0000
commit2e1003e2f7e42efc5771812b9ee6ed264803796c (patch)
tree1e70949071ddcf3eb2e63386e36d6083556a57c8 /src/cmd/go/internal/modload/load.go
parent0c5612092deb0a50c5a3d67babc1249049595558 (diff)
downloadgo-2e1003e2f7e42efc5771812b9ee6ed264803796c.tar.gz
go-2e1003e2f7e42efc5771812b9ee6ed264803796c.zip
cmd/go: replace reflect.DeepEqual with slices.Equal and maps.Equal
All of these maps and slices are made up of comparable types, so we can avoid the overhead of reflection entirely. Change-Id: If77dbe648a336ba729c171e84c9ff3f7e160297d Reviewed-on: https://go-review.googlesource.com/c/go/+/574597 Reviewed-by: Than McIntosh <thanm@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/cmd/go/internal/modload/load.go')
-rw-r--r--src/cmd/go/internal/modload/load.go11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go
index 51eb141d4b..408c109f5b 100644
--- a/src/cmd/go/internal/modload/load.go
+++ b/src/cmd/go/internal/modload/load.go
@@ -99,12 +99,13 @@ import (
"fmt"
"go/build"
"io/fs"
+ "maps"
"os"
"path"
pathpkg "path"
"path/filepath"
- "reflect"
"runtime"
+ "slices"
"sort"
"strings"
"sync"
@@ -1181,7 +1182,7 @@ func loadFromRoots(ctx context.Context, params loaderParams) *loader {
ld.error(err)
break
}
- if reflect.DeepEqual(rs.rootModules, ld.requirements.rootModules) {
+ if slices.Equal(rs.rootModules, ld.requirements.rootModules) {
// Something is deeply wrong. resolveMissingImports gave us a non-empty
// set of modules to add to the graph, but adding those modules had no
// effect — either they were already in the graph, or updateRoots did not
@@ -1319,7 +1320,7 @@ func (ld *loader) updateRequirements(ctx context.Context) (changed bool, err err
// imports.AnyTags, then we didn't necessarily load every package that
// contributes “direct” imports — so we can't safely mark existing direct
// dependencies in ld.requirements as indirect-only. Propagate them as direct.
- loadedDirect := ld.allPatternIsRoot && reflect.DeepEqual(ld.Tags, imports.AnyTags())
+ loadedDirect := ld.allPatternIsRoot && maps.Equal(ld.Tags, imports.AnyTags())
if loadedDirect {
direct = make(map[string]bool)
} else {
@@ -1465,7 +1466,7 @@ func (ld *loader) updateRequirements(ctx context.Context) (changed bool, err err
// packages present in the standard library. If it has changed, it's best to
// reload packages once more to be sure everything is stable.
changed = true
- } else if rs != ld.requirements && !reflect.DeepEqual(rs.rootModules, ld.requirements.rootModules) {
+ } else if rs != ld.requirements && !slices.Equal(rs.rootModules, ld.requirements.rootModules) {
// The roots of the module graph have changed in some way (not just the
// "direct" markings). Check whether the changes affected any of the loaded
// packages.
@@ -1779,7 +1780,7 @@ func (ld *loader) preloadRootModules(ctx context.Context, rootPkgs []string) (ch
ld.exitIfErrors(ctx)
return false
}
- if reflect.DeepEqual(rs.rootModules, ld.requirements.rootModules) {
+ if slices.Equal(rs.rootModules, ld.requirements.rootModules) {
// Something is deeply wrong. resolveMissingImports gave us a non-empty
// set of modules to add to the graph, but adding those modules had no
// effect — either they were already in the graph, or updateRoots did not