core: optimize IntrinsicGas

release/0.9.36
Felix Lange 10 years ago committed by Jeffrey Wilcke
parent a8889b092b
commit 0b22ad99c1
  1. 17
      core/state_transition.go

@ -77,12 +77,19 @@ func MessageGasValue(msg Message) *big.Int {
// with the given data. // with the given data.
func IntrinsicGas(data []byte) *big.Int { func IntrinsicGas(data []byte) *big.Int {
igas := new(big.Int).Set(params.TxGas) igas := new(big.Int).Set(params.TxGas)
for _, byt := range data { if len(data) > 0 {
if byt != 0 { var nz int64
igas.Add(igas, params.TxDataNonZeroGas) for _, byt := range data {
} else { if byt != 0 {
igas.Add(igas, params.TxDataZeroGas) 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 return igas
} }

Loading…
Cancel
Save