core/vm: improved push instructions

Improved push instructions by removing unnecessary big int allocations
and by making it int instead of big.Int
This commit is contained in:
Jeffrey Wilcke
2017-05-23 10:39:53 +02:00
parent 3ee75bec9f
commit a816e75662
2 changed files with 48 additions and 35 deletions

View File

@ -706,10 +706,23 @@ func makeLog(size int) executionFunc {
}
// make push instruction function
func makePush(size uint64, bsize *big.Int) executionFunc {
func makePush(size uint64, pushByteSize int) executionFunc {
return func(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
byts := getData(contract.Code, evm.interpreter.intPool.get().SetUint64(*pc+1), bsize)
stack.push(new(big.Int).SetBytes(byts))
codeLen := len(contract.Code)
startMin := codeLen
if int(*pc+1) < startMin {
startMin = int(*pc + 1)
}
endMin := codeLen
if startMin+pushByteSize < endMin {
endMin = startMin + pushByteSize
}
integer := evm.interpreter.intPool.get()
stack.push(integer.SetBytes(common.RightPadBytes(contract.Code[startMin:endMin], pushByteSize)))
*pc += size
return nil, nil
}