fix: Remove unnecessary loops for searchParent (#19353)

This commit is contained in:
jiuker 2024-03-27 23:12:14 +08:00 committed by GitHub
parent 364d3a0ac9
commit ec3a3bb10d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -523,20 +523,18 @@ func (d *dataUsageCache) searchParent(h dataUsageHash) *dataUsageHash {
want := h.Key()
if idx := strings.LastIndexByte(want, '/'); idx >= 0 {
if v := d.find(want[:idx]); v != nil {
for child := range v.Children {
if child == want {
found := hashPath(want[:idx])
return &found
}
_, ok := v.Children[want]
if ok {
found := hashPath(want[:idx])
return &found
}
}
}
for k, v := range d.Cache {
for child := range v.Children {
if child == want {
found := dataUsageHash(k)
return &found
}
_, ok := v.Children[want]
if ok {
found := dataUsageHash(k)
return &found
}
}
return nil