diff --git a/statistics/cmsketch.go b/statistics/cmsketch.go index 7a51a5e466157..ed924b39e0fc5 100644 --- a/statistics/cmsketch.go +++ b/statistics/cmsketch.go @@ -639,13 +639,8 @@ func (c *TopN) FindTopN(d []byte) int { if c == nil { return -1 } - match := false - idx := sort.Search(len(c.TopN), func(i int) bool { - cmpRst := bytes.Compare(c.TopN[i].Encoded, d) - if cmpRst == 0 { - match = true - } - return cmpRst >= 0 + idx, match := slices.BinarySearchFunc(c.TopN, d, func(a TopNMeta, b []byte) int { + return bytes.Compare(a.Encoded, b) }) if !match { return -1