use std slices package (#4008)

This commit is contained in:
fatedier
2024-02-20 12:01:41 +08:00
committed by GitHub
parent b6361fb143
commit 3e0c78233a
22 changed files with 75 additions and 84 deletions

View File

@@ -15,6 +15,8 @@
package nathole
import (
"cmp"
"slices"
"sync"
"time"
@@ -233,12 +235,12 @@ func (mhr *MakeHoleRecords) Recommand() (mode, index int) {
mhr.mu.Lock()
defer mhr.mu.Unlock()
maxScore := lo.MaxBy(mhr.scores, func(item, max *BehaviorScore) bool {
return item.Score > max.Score
})
if maxScore == nil {
if len(mhr.scores) == 0 {
return 0, 0
}
maxScore := slices.MaxFunc(mhr.scores, func(a, b *BehaviorScore) int {
return cmp.Compare(a.Score, b.Score)
})
maxScore.Score--
mhr.LastUpdateTime = time.Now()
return maxScore.Mode, maxScore.Index