archive/zip,cmd/compile: simplify the split function

Use strings to simplify the code.
This commit is contained in:
apocelipes 2024-08-02 19:21:18 +08:00
parent 11dbbaffe1
commit b95d617978
2 changed files with 4 additions and 16 deletions

View 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
}

View 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
}