]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: using strings.CutSuffix replace strings.HasSuffix and strings.TrimSuffix
authorcuiweixie <cuiweixie@gmail.com>
Tue, 27 Sep 2022 11:28:39 +0000 (19:28 +0800)
committerGopher Robot <gobot@golang.org>
Wed, 28 Sep 2022 16:47:59 +0000 (16:47 +0000)
Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11
Reviewed-on: https://go-review.googlesource.com/c/go/+/435138
Run-TryBot: xie cui <523516579@qq.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>

src/cmd/go/internal/modfetch/cache.go
src/cmd/go/internal/modfetch/codehost/git.go
src/cmd/go/internal/modfetch/fetch.go
src/cmd/go/internal/work/exec.go

index c1ed18736c3941e6e791c9e21919b23386bb3525..928eb1f70e07e4216989ec529a3a78f660c544e8 100644 (file)
@@ -710,8 +710,7 @@ func rewriteVersionList(dir string) (err error) {
                // 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)
                        }
index ac2dc2348eeb22583af408be178b605d12f12c56..7127d6afe93a08920c9462f7c1fe36e1793fb728 100644 (file)
@@ -262,8 +262,8 @@ func (r *gitRepo) loadRefs() (map[string]string, error) {
                        }
                }
                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)
                        }
                }
index 2e8c4c8acaacebf311a78124a7ca40abec77cc8d..003bc79fe959bfef3199dcc53aaa5f6cc57a7586 100644 (file)
@@ -698,9 +698,9 @@ func addModSumLocked(mod module.Version, h string) {
 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)
index 198d6081bb6babf7684178b1754a96c011ce5fb0..ca2f5a80b3d70a976ef87035a0c63d4937b85029 100644 (file)
@@ -642,12 +642,12 @@ OverlayLoop:
                        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