chore(tree): replace the self-defined 'min' to official one (#3975)

This commit is contained in:
Endless Paradox 2024-05-24 14:55:25 +08:00 committed by GitHub
parent 24d67647cb
commit 334160bab7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

15
tree.go
View File

@ -65,17 +65,10 @@ func (trees methodTrees) get(method string) *node {
return nil return nil
} }
func min(a, b int) int {
if a <= b {
return a
}
return b
}
func longestCommonPrefix(a, b string) int { func longestCommonPrefix(a, b string) int {
i := 0 i := 0
max := min(len(a), len(b)) max_ := min(len(a), len(b))
for i < max && a[i] == b[i] { for i < max_ && a[i] == b[i] {
i++ i++
} }
return i return i
@ -205,7 +198,7 @@ walk:
} }
// Check if a child with the next path byte exists // Check if a child with the next path byte exists
for i, max := 0, len(n.indices); i < max; i++ { for i, max_ := 0, len(n.indices); i < max_; i++ {
if c == n.indices[i] { if c == n.indices[i] {
parentFullPathIndex += len(n.path) parentFullPathIndex += len(n.path)
i = n.incrementChildPrio(i) i = n.incrementChildPrio(i)
@ -770,7 +763,7 @@ walk: // Outer loop for walking the tree
// Runes are up to 4 byte long, // Runes are up to 4 byte long,
// -4 would definitely be another rune. // -4 would definitely be another rune.
var off int var off int
for max := min(npLen, 3); off < max; off++ { for max_ := min(npLen, 3); off < max_; off++ {
if i := npLen - off; utf8.RuneStart(oldPath[i]) { if i := npLen - off; utf8.RuneStart(oldPath[i]) {
// read rune from cached path // read rune from cached path
rv, _ = utf8.DecodeRuneInString(oldPath[i:]) rv, _ = utf8.DecodeRuneInString(oldPath[i:])