all: unify big.Int zero checks, use common/math in more places (#3716)
* common/math: optimize PaddedBigBytes, use it more name old time/op new time/op delta PaddedBigBytes-8 71.1ns ± 5% 46.1ns ± 1% -35.15% (p=0.000 n=20+19) name old alloc/op new alloc/op delta PaddedBigBytes-8 48.0B ± 0% 32.0B ± 0% -33.33% (p=0.000 n=20+20) * all: unify big.Int zero checks Various checks were in use. This commit replaces them all with Int.Sign, which is cheaper and less code. eg templates: func before(x *big.Int) bool { return x.BitLen() == 0 } func after(x *big.Int) bool { return x.Sign() == 0 } func before(x *big.Int) bool { return x.BitLen() > 0 } func after(x *big.Int) bool { return x.Sign() != 0 } func before(x *big.Int) int { return x.Cmp(common.Big0) } func after(x *big.Int) int { return x.Sign() } * common/math, crypto/secp256k1: make ReadBits public in package math
Showing
- accounts/abi/bind/backends/simulated.go 1 addition, 1 deletionaccounts/abi/bind/backends/simulated.go
- accounts/abi/numbers.go 1 addition, 1 deletionaccounts/abi/numbers.go
- accounts/abi/packing.go 3 additions, 2 deletionsaccounts/abi/packing.go
- accounts/keystore/keystore_passphrase.go 2 additions, 2 deletionsaccounts/keystore/keystore_passphrase.go
- accounts/usbwallet/ledger_wallet.go 1 addition, 1 deletionaccounts/usbwallet/ledger_wallet.go
- common/math/big.go 25 additions, 8 deletionscommon/math/big.go
- common/math/big_test.go 23 additions, 0 deletionscommon/math/big_test.go
- contracts/chequebook/cheque.go 3 additions, 3 deletionscontracts/chequebook/cheque.go
- contracts/chequebook/cheque_test.go 1 addition, 1 deletioncontracts/chequebook/cheque_test.go
- core/headerchain.go 1 addition, 1 deletioncore/headerchain.go
- core/state/state_object.go 3 additions, 3 deletionscore/state/state_object.go
- core/tx_pool.go 1 addition, 1 deletioncore/tx_pool.go
- core/types/transaction.go 1 addition, 1 deletioncore/types/transaction.go
- core/types/transaction_signing.go 1 addition, 1 deletioncore/types/transaction_signing.go
- core/types/transaction_signing_test.go 1 addition, 1 deletioncore/types/transaction_signing_test.go
- core/vm/common.go 1 addition, 1 deletioncore/vm/common.go
- core/vm/evm.go 1 addition, 1 deletioncore/vm/evm.go
- core/vm/gas_table.go 3 additions, 3 deletionscore/vm/gas_table.go
- core/vm/instructions.go 12 additions, 11 deletionscore/vm/instructions.go
- core/vm/logger.go 2 additions, 1 deletioncore/vm/logger.go
Loading
Please register or sign in to comment