From a0791eb1758c1f4c271428aa4f4169961232881e Mon Sep 17 00:00:00 2001 From: Clayton Jacobs Date: Tue, 21 Aug 2018 16:41:36 +0800 Subject: [PATCH] Small optimization in gasprices (turned O(2n) to O(n) in worst case) --- eth/gasprice/gasprice.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/eth/gasprice/gasprice.go b/eth/gasprice/gasprice.go index 54325692c6..05c0131ba7 100644 --- a/eth/gasprice/gasprice.go +++ b/eth/gasprice/gasprice.go @@ -132,9 +132,10 @@ func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) { } } price := lastPrice - if len(blockPrices) > 0 { + blockPricesSize = len(blockPrices) + if blockPricesSize > 0 { sort.Sort(bigIntArray(blockPrices)) - price = blockPrices[(len(blockPrices)-1)*gpo.percentile/100] + price = blockPrices[(blockPricesSize-1)*gpo.percentile/100] } if price.Cmp(maxPrice) > 0 { price = new(big.Int).Set(maxPrice)