From 6fc8d0dc641e1d031ad37e0e34a0d34a3eade56c Mon Sep 17 00:00:00 2001 From: riyueguang Date: Tue, 25 Mar 2025 01:35:40 +0800 Subject: [PATCH] refactor: use the built-in max/min to simplify the code (#24112) Signed-off-by: riyueguang --- math/int_test.go | 18 ++---------------- math/uint_test.go | 18 ++---------------- store/pruning/manager.go | 5 +---- 3 files changed, 5 insertions(+), 36 deletions(-) diff --git a/math/int_test.go b/math/int_test.go index e09caf6ae5..6daef7e85a 100644 --- a/math/int_test.go +++ b/math/int_test.go @@ -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}, diff --git a/math/uint_test.go b/math/uint_test.go index 62a081d515..1bf8b0b507 100644 --- a/math/uint_test.go +++ b/math/uint_test.go @@ -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, diff --git a/store/pruning/manager.go b/store/pruning/manager.go index 9a99e49151..57a6773634 100644 --- a/store/pruning/manager.go +++ b/store/pruning/manager.go @@ -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.