core, txpool: less allocations when handling transactions (#21232)
* core: use uint64 for total tx costs instead of big.Int * core: added local tx pool test case * core, crypto: various allocation savings regarding tx handling * Update core/tx_list.go * core: added tx.GasPriceIntCmp for comparison without allocation adds a method to remove unneeded allocation in comparison to tx.gasPrice * core: handle pools full of locals better * core/tests: benchmark for tx_list * core/txlist, txpool: save a reheap operation, avoid some bigint allocs Co-authored-by: Martin Holst Swende <martin@swende.se>
This commit is contained in:
committed by
GitHub
parent
8dfd66f701
commit
af5c97aebe
@ -18,6 +18,7 @@ package math
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/bits"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
@ -87,13 +88,12 @@ func SafeSub(x, y uint64) (uint64, bool) {
|
||||
|
||||
// SafeAdd returns the result and whether overflow occurred.
|
||||
func SafeAdd(x, y uint64) (uint64, bool) {
|
||||
return x + y, y > MaxUint64-x
|
||||
sum, carry := bits.Add64(x, y, 0)
|
||||
return sum, carry != 0
|
||||
}
|
||||
|
||||
// SafeMul returns multiplication result and whether overflow occurred.
|
||||
func SafeMul(x, y uint64) (uint64, bool) {
|
||||
if x == 0 || y == 0 {
|
||||
return 0, false
|
||||
}
|
||||
return x * y, y > MaxUint64/x
|
||||
hi, lo := bits.Mul64(x, y)
|
||||
return lo, hi != 0
|
||||
}
|
||||
|
Reference in New Issue
Block a user