mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
core/vm: optimze emit event using uint256.WriteToArray32
This commit is contained in:
parent
0ec63272bf
commit
a1334f0199
2 changed files with 36 additions and 1 deletions
|
|
@ -933,7 +933,7 @@ func makeLog(size int) executionFunc {
|
|||
mStart, mSize := stack.pop(), stack.pop()
|
||||
for i := 0; i < size; i++ {
|
||||
addr := stack.pop()
|
||||
topics[i] = addr.Bytes32()
|
||||
addr.WriteToArray32((*[32]byte)(&topics[i]))
|
||||
}
|
||||
|
||||
d := scope.Memory.GetCopy(mStart.Uint64(), mSize.Uint64())
|
||||
|
|
|
|||
|
|
@ -1008,3 +1008,38 @@ func TestOpCLZ(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkLog3(b *testing.B) {
|
||||
var (
|
||||
statedb, _ = state.New(types.EmptyRootHash, state.NewDatabaseForTesting())
|
||||
evm = NewEVM(BlockContext{BlockNumber: big.NewInt(1), Time: 1, Random: &common.Hash{}}, statedb, params.MergedTestChainConfig, Config{})
|
||||
startGas uint64 = 100_000_000
|
||||
value = uint256.NewInt(0)
|
||||
contract = NewContract(common.Address{}, common.Address{}, value, startGas, nil)
|
||||
scope = &ScopeContext{
|
||||
Contract: contract,
|
||||
Memory: NewMemory(),
|
||||
Stack: new(Stack),
|
||||
}
|
||||
)
|
||||
// get log3 executor
|
||||
exec := makeLog(3)
|
||||
for b.Loop() {
|
||||
// memory data
|
||||
data := []byte("hello world, this is log data")
|
||||
scope.Memory.Resize(1024)
|
||||
scope.Memory.Set(0, uint64(len(data)), data)
|
||||
|
||||
// LOG3
|
||||
// stack: mStart, mSize, topic1, topic2, topic3
|
||||
scope.Stack.push(uint256.NewInt(1))
|
||||
scope.Stack.push(uint256.NewInt(2))
|
||||
scope.Stack.push(uint256.NewInt(3))
|
||||
scope.Stack.push(uint256.NewInt(uint64(len(data)))) // mSize
|
||||
scope.Stack.push(uint256.NewInt(0)) // mStart
|
||||
_, err := exec(nil, evm, scope)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue