x/model: fast-path CompareFold for unequal lengths

This commit is contained in:
Blake Mizerany 2024-04-05 22:17:07 -07:00
parent 2e600aa398
commit a187851900

View File

@ -308,13 +308,17 @@ func (r Name) CompareFold(o Name) int {
}
func compareFold(a, b string) int {
// fast-path for unequal lengths
if n := cmp.Compare(len(a), len(b)); n != 0 {
return n
}
for i := 0; i < len(a) && i < len(b); i++ {
ca, cb := downcase(a[i]), downcase(b[i])
if n := cmp.Compare(ca, cb); n != 0 {
return n
}
}
return cmp.Compare(len(a), len(b))
return 0
}
func downcase(c byte) byte {