From 3775d61ccbfe86fa0754a0660ca115ba9f9e6bfc Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 3 Feb 2021 15:07:37 +0300 Subject: [PATCH] [#365] settlement/basic: Use big.Int constructor for unification Check if `new(big.Int)` will be efficient later and replace all `big.NewInt()` in code or leave it as it is. Signed-off-by: Alex Vanin --- pkg/innerring/processors/settlement/basic/collect.go | 2 +- pkg/innerring/processors/settlement/basic/distribute.go | 2 +- .../processors/settlement/basic/distribute_test.go | 8 ++++---- pkg/innerring/processors/settlement/basic/util.go | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/innerring/processors/settlement/basic/collect.go b/pkg/innerring/processors/settlement/basic/collect.go index f78446741..4e70b2179 100644 --- a/pkg/innerring/processors/settlement/basic/collect.go +++ b/pkg/innerring/processors/settlement/basic/collect.go @@ -93,7 +93,7 @@ func calculateBasicSum(size, rate uint64, ln int) *big.Int { total := size * uint64(ln) - price := new(big.Int).SetUint64(total) + price := big.NewInt(0).SetUint64(total) price.Mul(price, bigRate) price.Div(price, bigGB) diff --git a/pkg/innerring/processors/settlement/basic/distribute.go b/pkg/innerring/processors/settlement/basic/distribute.go index 32e9ff045..6d16f9cb7 100644 --- a/pkg/innerring/processors/settlement/basic/distribute.go +++ b/pkg/innerring/processors/settlement/basic/distribute.go @@ -46,7 +46,7 @@ func (inc *IncomeSettlementContext) Distribute() { func normalizedValue(n, total, limit *big.Int) *big.Int { if limit.Cmp(bigZero) == 0 { - return new(big.Int) + return big.NewInt(0) } n.Mul(n, limit) diff --git a/pkg/innerring/processors/settlement/basic/distribute_test.go b/pkg/innerring/processors/settlement/basic/distribute_test.go index 959ad7f9b..24eb0db3d 100644 --- a/pkg/innerring/processors/settlement/basic/distribute_test.go +++ b/pkg/innerring/processors/settlement/basic/distribute_test.go @@ -44,10 +44,10 @@ func TestNormalizedValues(t *testing.T) { } func testNormalizedValues(t *testing.T, c normalizedValueCase) { - n := new(big.Int).SetUint64(c.n) - total := new(big.Int).SetUint64(c.total) - limit := new(big.Int).SetUint64(c.limit) - exp := new(big.Int).SetUint64(c.expected) + n := big.NewInt(0).SetUint64(c.n) + total := big.NewInt(0).SetUint64(c.total) + limit := big.NewInt(0).SetUint64(c.limit) + exp := big.NewInt(0).SetUint64(c.expected) got := normalizedValue(n, total, limit) require.Zero(t, exp.Cmp(got), c.name) diff --git a/pkg/innerring/processors/settlement/basic/util.go b/pkg/innerring/processors/settlement/basic/util.go index 64ee193cf..258bae46f 100644 --- a/pkg/innerring/processors/settlement/basic/util.go +++ b/pkg/innerring/processors/settlement/basic/util.go @@ -17,12 +17,12 @@ func (t *NodeSizeTable) Put(id []byte, avg uint64) { } func (t *NodeSizeTable) Total() *big.Int { - return new(big.Int).SetUint64(t.total) + return big.NewInt(0).SetUint64(t.total) } func (t *NodeSizeTable) Iterate(f func([]byte, *big.Int)) { for k, v := range t.prices { - n := new(big.Int).SetUint64(v) + n := big.NewInt(0).SetUint64(v) f([]byte(k), n) } }