refactor: use the built-in max/min to simplify the code (#24112)
Signed-off-by: riyueguang <rustruby@outlook.com>
This commit is contained in:
parent
85a33eb62b
commit
6fc8d0dc64
@ -221,20 +221,6 @@ func (s *intTestSuite) TestIdentInt() {
|
||||
}
|
||||
}
|
||||
|
||||
func minint(i1, i2 int64) int64 {
|
||||
if i1 < i2 {
|
||||
return i1
|
||||
}
|
||||
return i2
|
||||
}
|
||||
|
||||
func maxint(i1, i2 int64) int64 {
|
||||
if i1 > i2 {
|
||||
return i1
|
||||
}
|
||||
return i2
|
||||
}
|
||||
|
||||
func (s *intTestSuite) TestArithInt() {
|
||||
for d := 0; d < 1000; d++ {
|
||||
n1 := int64(rand.Int31())
|
||||
@ -254,8 +240,8 @@ func (s *intTestSuite) TestArithInt() {
|
||||
{i1.SubRaw(n2), n1 - n2},
|
||||
{i1.MulRaw(n2), n1 * n2},
|
||||
{i1.QuoRaw(n2), n1 / n2},
|
||||
{math.MinInt(i1, i2), minint(n1, n2)},
|
||||
{math.MaxInt(i1, i2), maxint(n1, n2)},
|
||||
{math.MinInt(i1, i2), min(n1, n2)},
|
||||
{math.MaxInt(i1, i2), max(n1, n2)},
|
||||
{i1.Neg(), -n1},
|
||||
{i1.Abs(), n1},
|
||||
{i1.Neg().Abs(), n1},
|
||||
|
||||
@ -136,8 +136,8 @@ func (s *uintTestSuite) TestArithUint() {
|
||||
{u1.AddUint64(n2), n1 + n2},
|
||||
{u1.MulUint64(n2), n1 * n2},
|
||||
{u1.QuoUint64(n2), n1 / n2},
|
||||
{sdkmath.MinUint(u1, u2), minuint(n1, n2)},
|
||||
{sdkmath.MaxUint(u1, u2), maxuint(n1, n2)},
|
||||
{sdkmath.MinUint(u1, u2), min(n1, n2)},
|
||||
{sdkmath.MaxUint(u1, u2), max(n1, n2)},
|
||||
{u1.Incr(), n1 + 1},
|
||||
}
|
||||
|
||||
@ -316,20 +316,6 @@ func (s *uintTestSuite) TestRelativePow() {
|
||||
}
|
||||
}
|
||||
|
||||
func minuint(i1, i2 uint64) uint64 {
|
||||
if i1 < i2 {
|
||||
return i1
|
||||
}
|
||||
return i2
|
||||
}
|
||||
|
||||
func maxuint(i1, i2 uint64) uint64 {
|
||||
if i1 > i2 {
|
||||
return i1
|
||||
}
|
||||
return i2
|
||||
}
|
||||
|
||||
func TestRoundTripMarshalToUint(t *testing.T) {
|
||||
values := []uint64{
|
||||
0,
|
||||
|
||||
@ -130,10 +130,7 @@ func (m *Manager) GetPruningHeight(height int64) int64 {
|
||||
// the snapshot `m.pruneSnapshotHeights[0]` is already operated,
|
||||
// so we can prune upto `m.pruneSnapshotHeights[0] + int64(m.snapshotInterval) - 1`
|
||||
snHeight := m.pruneSnapshotHeights[0] + int64(m.snapshotInterval) - 1
|
||||
if snHeight < pruneHeight {
|
||||
return snHeight
|
||||
}
|
||||
return pruneHeight
|
||||
return min(snHeight, pruneHeight)
|
||||
}
|
||||
|
||||
// LoadSnapshotHeights loads the snapshot heights from the database as a crash recovery.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user