statistics: use slices.BinarySearchFunc to simple TopN.FindTopN (#46996)
ref pingcap/tidb#45933
This commit is contained in:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user