diff options
author | Felix Lange <fjl@twurst.com> | 2015-06-25 20:46:44 +0800 |
---|---|---|
committer | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-06-30 00:51:48 +0800 |
commit | 0b22ad99c18b6aaa77afc32113c308f12a07e843 (patch) | |
tree | 5ec59df9a5ab0f0df247ca8dfdf51404ae224b77 /core | |
parent | a8889b092bfb2a1b61733883caf11e07eb072d69 (diff) | |
download | dexon-0b22ad99c18b6aaa77afc32113c308f12a07e843.tar dexon-0b22ad99c18b6aaa77afc32113c308f12a07e843.tar.gz dexon-0b22ad99c18b6aaa77afc32113c308f12a07e843.tar.bz2 dexon-0b22ad99c18b6aaa77afc32113c308f12a07e843.tar.lz dexon-0b22ad99c18b6aaa77afc32113c308f12a07e843.tar.xz dexon-0b22ad99c18b6aaa77afc32113c308f12a07e843.tar.zst dexon-0b22ad99c18b6aaa77afc32113c308f12a07e843.zip |
core: optimize IntrinsicGas
Diffstat (limited to 'core')
-rw-r--r-- | core/state_transition.go | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/core/state_transition.go b/core/state_transition.go index 2c8770cbe..5844ad3c8 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -77,12 +77,19 @@ func MessageGasValue(msg Message) *big.Int { // with the given data. func IntrinsicGas(data []byte) *big.Int { igas := new(big.Int).Set(params.TxGas) - for _, byt := range data { - if byt != 0 { - igas.Add(igas, params.TxDataNonZeroGas) - } else { - igas.Add(igas, params.TxDataZeroGas) + if len(data) > 0 { + var nz int64 + for _, byt := range data { + if byt != 0 { + nz++ + } } + m := big.NewInt(nz) + m.Mul(m, params.TxDataNonZeroGas) + igas.Add(igas, m) + m.SetInt64(int64(len(data)) - nz) + m.Mul(m, params.TxDataZeroGas) + igas.Add(igas, m) } return igas } |