mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-13 09:50:00 +08:00
update:use builtin cmp func (#4879)
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/mathx"
|
|
||||||
"github.com/zeromicro/go-zero/core/proc"
|
"github.com/zeromicro/go-zero/core/proc"
|
||||||
"github.com/zeromicro/go-zero/core/stat"
|
"github.com/zeromicro/go-zero/core/stat"
|
||||||
"github.com/zeromicro/go-zero/core/stringx"
|
"github.com/zeromicro/go-zero/core/stringx"
|
||||||
@@ -264,7 +263,7 @@ func (ew *errorWindow) add(reason string) {
|
|||||||
ew.lock.Lock()
|
ew.lock.Lock()
|
||||||
ew.reasons[ew.index] = fmt.Sprintf("%s %s", time.Now().Format(timeFormat), reason)
|
ew.reasons[ew.index] = fmt.Sprintf("%s %s", time.Now().Format(timeFormat), reason)
|
||||||
ew.index = (ew.index + 1) % numHistoryReasons
|
ew.index = (ew.index + 1) % numHistoryReasons
|
||||||
ew.count = mathx.MinInt(ew.count+1, numHistoryReasons)
|
ew.count = min(ew.count+1, numHistoryReasons)
|
||||||
ew.lock.Unlock()
|
ew.lock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,13 @@
|
|||||||
package mathx
|
package mathx
|
||||||
|
|
||||||
// MaxInt returns the larger one of a and b.
|
// MaxInt returns the larger one of a and b.
|
||||||
|
// Deprecated: use builtin max instead.
|
||||||
func MaxInt(a, b int) int {
|
func MaxInt(a, b int) int {
|
||||||
if a > b {
|
return max(a, b)
|
||||||
return a
|
|
||||||
}
|
|
||||||
|
|
||||||
return b
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MinInt returns the smaller one of a and b.
|
// MinInt returns the smaller one of a and b.
|
||||||
|
// Deprecated: use builtin min instead.
|
||||||
func MinInt(a, b int) int {
|
func MinInt(a, b int) int {
|
||||||
if a < b {
|
return min(a, b)
|
||||||
return a
|
|
||||||
}
|
|
||||||
|
|
||||||
return b
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"cmp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/mathx"
|
|
||||||
"github.com/zeromicro/go-zero/core/stringx"
|
"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, ".")
|
fields1, fields2 := strings.Split(v1, "."), strings.Split(v2, ".")
|
||||||
ver1, ver2 := strsToInts(fields1), strsToInts(fields2)
|
ver1, ver2 := strsToInts(fields1), strsToInts(fields2)
|
||||||
ver1len, ver2len := len(ver1), len(ver2)
|
ver1len, ver2len := len(ver1), len(ver2)
|
||||||
shorter := mathx.MinInt(ver1len, ver2len)
|
shorter := min(ver1len, ver2len)
|
||||||
|
|
||||||
for i := 0; i < shorter; i++ {
|
for i := 0; i < shorter; i++ {
|
||||||
if ver1[i] == ver2[i] {
|
if ver1[i] == ver2[i] {
|
||||||
@@ -50,14 +50,7 @@ func compare(v1, v2 string) int {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return cmp.Compare(ver1len, ver2len)
|
||||||
if ver1len < ver2len {
|
|
||||||
return -1
|
|
||||||
} else if ver1len == ver2len {
|
|
||||||
return 0
|
|
||||||
} else {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func strsToInts(strs []string) []int64 {
|
func strsToInts(strs []string) []int64 {
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/zeromicro/go-zero/core/lang"
|
"github.com/zeromicro/go-zero/core/lang"
|
||||||
"github.com/zeromicro/go-zero/core/mathx"
|
|
||||||
"google.golang.org/grpc/resolver"
|
"google.golang.org/grpc/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -47,7 +46,7 @@ func TestDirectBuilder_Build(t *testing.T) {
|
|||||||
}, cc, resolver.BuildOptions{})
|
}, cc, resolver.BuildOptions{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
size := mathx.MinInt(test, subsetSize)
|
size := min(test, subsetSize)
|
||||||
assert.Equal(t, size, len(cc.state.Addresses))
|
assert.Equal(t, size, len(cc.state.Addresses))
|
||||||
m := make(map[string]lang.PlaceholderType)
|
m := make(map[string]lang.PlaceholderType)
|
||||||
for _, each := range cc.state.Addresses {
|
for _, each := range cc.state.Addresses {
|
||||||
|
|||||||
Reference in New Issue
Block a user