chore(fs): slightly reduce memory usage of IsParent (#10223)

### Purpose

Small optimizations for IsParent and IsInternal, to avoid needless
allocations.
This commit is contained in:
Daniil Gentili
2025-07-31 14:48:04 +00:00
committed by GitHub
parent 6e26fab3a0
commit 953944e54e
2 changed files with 13 additions and 6 deletions
+9 -3
View File
@@ -169,10 +169,16 @@ func IsParent(path, parent string) bool {
// not be caught below.
return path != "/"
}
if parent[len(parent)-1] != PathSeparator {
parent += pathSeparatorString
if parent[len(parent)-1] == PathSeparator {
return strings.HasPrefix(path, parent)
}
return strings.HasPrefix(path, parent)
if !strings.HasPrefix(path, parent) {
return false
}
if len(path) <= len(parent) {
return false
}
return path[len(parent)] == PathSeparator
}
func CommonPrefix(first, second string) string {