update:use builtin cmp func (#4879)

This commit is contained in:
me-cs
2025-05-22 23:19:13 +08:00
committed by GitHub
parent e3c371ac89
commit b109b3ef4c
4 changed files with 9 additions and 24 deletions

View File

@@ -8,7 +8,6 @@ import (
"sync"
"time"
"github.com/zeromicro/go-zero/core/mathx"
"github.com/zeromicro/go-zero/core/proc"
"github.com/zeromicro/go-zero/core/stat"
"github.com/zeromicro/go-zero/core/stringx"
@@ -264,7 +263,7 @@ func (ew *errorWindow) add(reason string) {
ew.lock.Lock()
ew.reasons[ew.index] = fmt.Sprintf("%s %s", time.Now().Format(timeFormat), reason)
ew.index = (ew.index + 1) % numHistoryReasons
ew.count = mathx.MinInt(ew.count+1, numHistoryReasons)
ew.count = min(ew.count+1, numHistoryReasons)
ew.lock.Unlock()
}

View File

@@ -1,19 +1,13 @@
package mathx
// MaxInt returns the larger one of a and b.
// Deprecated: use builtin max instead.
func MaxInt(a, b int) int {
if a > b {
return a
}
return b
return max(a, b)
}
// MinInt returns the smaller one of a and b.
// Deprecated: use builtin min instead.
func MinInt(a, b int) int {
if a < b {
return a
}
return b
return min(a, b)
}

View File

@@ -1,10 +1,10 @@
package utils
import (
"cmp"
"strconv"
"strings"
"github.com/zeromicro/go-zero/core/mathx"
"github.com/zeromicro/go-zero/core/stringx"
)
@@ -39,7 +39,7 @@ func compare(v1, v2 string) int {
fields1, fields2 := strings.Split(v1, "."), strings.Split(v2, ".")
ver1, ver2 := strsToInts(fields1), strsToInts(fields2)
ver1len, ver2len := len(ver1), len(ver2)
shorter := mathx.MinInt(ver1len, ver2len)
shorter := min(ver1len, ver2len)
for i := 0; i < shorter; i++ {
if ver1[i] == ver2[i] {
@@ -50,14 +50,7 @@ func compare(v1, v2 string) int {
return 1
}
}
if ver1len < ver2len {
return -1
} else if ver1len == ver2len {
return 0
} else {
return 1
}
return cmp.Compare(ver1len, ver2len)
}
func strsToInts(strs []string) []int64 {