xie cui has uploaded this change for review.
cmd/go: using strings.CutSuffix replace strings.HasSuffix and strings.TrimSuffix
Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11
---
M src/cmd/go/internal/modfetch/cache.go
M src/cmd/go/internal/modfetch/codehost/git.go
M src/cmd/go/internal/modfetch/fetch.go
M src/cmd/go/internal/work/exec.go
4 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/src/cmd/go/internal/modfetch/cache.go b/src/cmd/go/internal/modfetch/cache.go
index c1ed187..928eb1f 100644
--- a/src/cmd/go/internal/modfetch/cache.go
+++ b/src/cmd/go/internal/modfetch/cache.go
@@ -710,8 +710,7 @@
// involved in module graph construction, many *.zip files
// will never be requested.
name := info.Name()
- if strings.HasSuffix(name, ".mod") {
- v := strings.TrimSuffix(name, ".mod")
+ if v, found := strings.CutSuffix(name, ".mod"); found {
if v != "" && module.CanonicalVersion(v) == v {
list = append(list, v)
}
diff --git a/src/cmd/go/internal/modfetch/codehost/git.go b/src/cmd/go/internal/modfetch/codehost/git.go
index ac2dc23..7127d6a 100644
--- a/src/cmd/go/internal/modfetch/codehost/git.go
+++ b/src/cmd/go/internal/modfetch/codehost/git.go
@@ -262,8 +262,8 @@
}
}
for ref, hash := range refs {
- if strings.HasSuffix(ref, "^{}") { // record unwrapped annotated tag as value of tag
- refs[strings.TrimSuffix(ref, "^{}")] = hash
+ if k, found := strings.CutSuffix(ref, "^{}"); found { // record unwrapped annotated tag as value of tag
+ refs[k] = hash
delete(refs, ref)
}
}
diff --git a/src/cmd/go/internal/modfetch/fetch.go b/src/cmd/go/internal/modfetch/fetch.go
index 2e8c4c8..8fe848a 100644
--- a/src/cmd/go/internal/modfetch/fetch.go
+++ b/src/cmd/go/internal/modfetch/fetch.go
@@ -698,9 +698,9 @@
func checkSumDB(mod module.Version, h string) error {
modWithoutSuffix := mod
noun := "module"
- if strings.HasSuffix(mod.Version, "/go.mod") {
+ if after, found := strings.CutSuffix(mod.Version, "/go.mod"); found {
noun = "go.mod"
- modWithoutSuffix.Version = strings.TrimSuffix(mod.Version, "/go.mod")
+ modWithoutSuffix.Version = after
}
db, lines, err := lookupSumDB(mod)
diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go
index e0b9472..af204e7 100644
--- a/src/cmd/go/internal/work/exec.go
+++ b/src/cmd/go/internal/work/exec.go
@@ -634,12 +634,12 @@
var sourceFile string
var coverFile string
var key string
- if strings.HasSuffix(file, ".cgo1.go") {
+ if key, found := strings.CutSuffix(file, ".cgo1.go"); found {
// cgo files have absolute paths
base := filepath.Base(file)
sourceFile = file
coverFile = objdir + base
- key = strings.TrimSuffix(base, ".cgo1.go") + ".go"
+ key = key + ".go"
} else {
sourceFile = filepath.Join(a.Package.Dir, file)
coverFile = objdir + file
To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Michael Matloob, xie cui.
Patch set 1:Run-TryBot +1Auto-Submit +1Code-Review +2
Attention is currently required from: Michael Matloob, xie cui.
1 comment:
File src/cmd/go/internal/work/exec.go:
This variable needs a different name.
The use of `:=` here introduces another variable named `key` that shadows the one declared on the previous line. That causes the assignments at line 642 and 646 to write to the inner `key` variable, which leaves the outer `key` variable set to the empty string.
To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan Mills, Michael Matloob, xie cui.
xie cui uploaded patch set #2 to this change.
The following approvals got outdated and were removed: Auto-Submit+1 by Bryan Mills, Run-TryBot+1 by Bryan Mills, TryBot-Result-1 by Gopher Robot
cmd/go: using strings.CutSuffix replace strings.HasSuffix and strings.TrimSuffix
Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11
---
M src/cmd/go/internal/modfetch/cache.go
M src/cmd/go/internal/modfetch/codehost/git.go
M src/cmd/go/internal/modfetch/fetch.go
M src/cmd/go/internal/work/exec.go
4 files changed, 17 insertions(+), 8 deletions(-)
To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan Mills, Michael Matloob.
Patch set 2:Run-TryBot +1
Attention is currently required from: Bryan Mills, Michael Matloob.
1 comment:
File src/cmd/go/internal/work/exec.go:
This variable needs a different name. […]
Done, Thanks!
To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan Mills, Michael Matloob, xie cui.
1 comment:
File src/cmd/go/internal/work/exec.go:
Patch Set #2, Line 638: if key, found = strings.CutSuffix(file, ".cgo1.go"); found {
I'd rather see a name other than "key" here, because this is not the key. How about
if base, found := strings.CutSuffix(...); found {To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan Mills, Michael Matloob, xie cui.
xie cui uploaded patch set #3 to this change.
The following approvals got outdated and were removed: Run-TryBot+1 by xie cui, TryBot-Result+1 by Gopher Robot
cmd/go: using strings.CutSuffix replace strings.HasSuffix and strings.TrimSuffix
Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11
---
M src/cmd/go/internal/modfetch/cache.go
M src/cmd/go/internal/modfetch/codehost/git.go
M src/cmd/go/internal/modfetch/fetch.go
M src/cmd/go/internal/work/exec.go
4 files changed, 18 insertions(+), 10 deletions(-)
To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan Mills, Michael Matloob.
Patch set 3:Run-TryBot +1
Attention is currently required from: Bryan Mills, Ian Lance Taylor, Michael Matloob.
1 comment:
File src/cmd/go/internal/work/exec.go:
Patch Set #2, Line 638: if key, found = strings.CutSuffix(file, ".cgo1.go"); found {
I'd rather see a name other than "key" here, because this is not the key. How about […]
Done
To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan Mills, Ian Lance Taylor, Michael Matloob, xie cui.
1 comment:
File src/cmd/go/internal/modfetch/fetch.go:
Patch Set #3, Line 701: after
The variable name 'after' doesn't seem like a good fit here given that CutSuffix, not CutPrefix, is being used here.
To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan Mills, Ian Lance Taylor, Michael Matloob, xie cui.
Patch set 3:Code-Review +1
Attention is currently required from: Bryan Mills, Ian Lance Taylor, Michael Matloob.
Patch set 4:Run-TryBot +1
Attention is currently required from: Bryan Mills, Dmitri Shuralyov, Ian Lance Taylor, Michael Matloob.
1 comment:
File src/cmd/go/internal/modfetch/fetch.go:
Patch Set #3, Line 701: after
The variable name 'after' doesn't seem like a good fit here given that CutSuffix, not CutPrefix, is […]
Done
To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Ian Lance Taylor, Michael Matloob, xie cui.
Patch set 4:Run-TryBot +1Auto-Submit +1Code-Review +2
To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.
Gopher Robot submitted this change.
cmd/go: using strings.CutSuffix replace strings.HasSuffix and strings.TrimSuffix
Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11
Reviewed-on: https://go-review.googlesource.com/c/go/+/435138
Run-TryBot: xie cui <5235...@qq.com>
TryBot-Result: Gopher Robot <go...@golang.org>
Reviewed-by: Dmitri Shuralyov <dmit...@google.com>
Reviewed-by: Bryan Mills <bcm...@google.com>
Auto-Submit: Bryan Mills <bcm...@google.com>
Run-TryBot: Bryan Mills <bcm...@google.com>
---
M src/cmd/go/internal/modfetch/cache.go
M src/cmd/go/internal/modfetch/codehost/git.go
M src/cmd/go/internal/modfetch/fetch.go
M src/cmd/go/internal/work/exec.go
4 files changed, 25 insertions(+), 10 deletions(-)
index 2e8c4c8..003bc79 100644
--- a/src/cmd/go/internal/modfetch/fetch.go
+++ b/src/cmd/go/internal/modfetch/fetch.go
@@ -698,9 +698,9 @@
func checkSumDB(mod module.Version, h string) error {
modWithoutSuffix := mod
noun := "module"
- if strings.HasSuffix(mod.Version, "/go.mod") {
+ if before, found := strings.CutSuffix(mod.Version, "/go.mod"); found {
noun = "go.mod"
- modWithoutSuffix.Version = strings.TrimSuffix(mod.Version, "/go.mod")
+ modWithoutSuffix.Version = before
}
db, lines, err := lookupSumDB(mod)
diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go
index 198d608..ca2f5a8 100644
--- a/src/cmd/go/internal/work/exec.go
+++ b/src/cmd/go/internal/work/exec.go
@@ -642,12 +642,12 @@
var sourceFile string
var coverFile string
var key string
- if strings.HasSuffix(file, ".cgo1.go") {
+ if base, found := strings.CutSuffix(file, ".cgo1.go"); found {
// cgo files have absolute paths
- base := filepath.Base(file)
+ base = filepath.Base(base)
sourceFile = file
- coverFile = objdir + base
- key = strings.TrimSuffix(base, ".cgo1.go") + ".go"
+ coverFile = objdir + base + ".cgo1.go"
+ key = base + ".go"
} else {
sourceFile = filepath.Join(p.Dir, file)
coverFile = objdir + file
To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.