core: optimize IntrinsicGas

This commit is contained in:
Felix Lange 2015-06-25 14:46:44 +02:00 committed by Jeffrey Wilcke
parent a8889b092b
commit 0b22ad99c1

View File

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