refactor: use the built-in max/min to simplify the code (#24112)

Signed-off-by: riyueguang <rustruby@outlook.com>
This commit is contained in:
riyueguang 2025-03-25 01:35:40 +08:00 committed by GitHub
parent 85a33eb62b
commit 6fc8d0dc64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 36 deletions

View File

@ -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},

View File

@ -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,

View File

@ -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.