mirror of https://github.com/golang/go.git
archive/zip,cmd/compile: simplify the split function
Use strings to simplify the code.
This commit is contained in:
parent
11dbbaffe1
commit
b95d617978
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue