Commit 0b22ad99 authored by Felix Lange's avatar Felix Lange Committed by Jeffrey Wilcke

core: optimize IntrinsicGas

parent a8889b09
...@@ -77,12 +77,19 @@ func MessageGasValue(msg Message) *big.Int { ...@@ -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)
if len(data) > 0 {
var nz int64
for _, byt := range data { for _, byt := range data {
if byt != 0 { if byt != 0 {
igas.Add(igas, params.TxDataNonZeroGas) nz++
} else { }
igas.Add(igas, params.TxDataZeroGas)
} }
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
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment