]> Cypherpunks repositories - gostls13.git/commitdiff
archive/zip,cmd/compile: simplify the split function
authorapocelipes <seve3r@outlook.com>
Fri, 2 Aug 2024 11:33:30 +0000 (11:33 +0000)
committerGopher Robot <gobot@golang.org>
Sat, 3 Aug 2024 01:05:29 +0000 (01:05 +0000)
Use strings to simplify the code.

This is a follow-up for the CL 586715.

Change-Id: I9e5470ec271e8af1ad4ddbb5f01f43a8a4879557
GitHub-Last-Rev: b95d6179781053ea8ec9fc8ad2e18607fd35c5bb
GitHub-Pull-Request: golang/go#68713
Reviewed-on: https://go-review.googlesource.com/c/go/+/602697
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/archive/zip/reader.go
src/cmd/compile/internal/staticdata/embed.go

index fc9b1cf67c06d9a21c1b83fb6eca20510c169265..2246d56558bbeea48ea23c3214eaca7d4afaf615 100644 (file)
@@ -902,14 +902,8 @@ func (r *Reader) Open(name string) (fs.File, error) {
 }
 
 func split(name string) (dir, elem string, isDir bool) {
-       if len(name) > 0 && name[len(name)-1] == '/' {
-               isDir = true
-               name = name[:len(name)-1]
-       }
-       i := len(name) - 1
-       for i >= 0 && name[i] != '/' {
-               i--
-       }
+       name, isDir = strings.CutSuffix(name, "/")
+       i := strings.LastIndexByte(name, '/')
        if i < 0 {
                return ".", name, isDir
        }
index a4d493ce5e359ea37b6334686b37d247969a7d94..be939db877fd34a56a87364625efa89a614e7f4b 100644 (file)
@@ -80,14 +80,8 @@ func embedKind(typ *types.Type) int {
 }
 
 func embedFileNameSplit(name string) (dir, elem string, isDir bool) {
-       if name[len(name)-1] == '/' {
-               isDir = true
-               name = name[:len(name)-1]
-       }
-       i := len(name) - 1
-       for i >= 0 && name[i] != '/' {
-               i--
-       }
+       name, isDir = strings.CutSuffix(name, "/")
+       i := strings.LastIndexByte(name, '/')
        if i < 0 {
                return ".", name, isDir
        }