mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
core/vm: make a 0 alloc stack
This commit is contained in:
parent
187f3cba26
commit
cf2eb01815
2 changed files with 15 additions and 8 deletions
|
|
@ -345,7 +345,7 @@ func gasCreate2Eip3860(evm *EVM, contract *Contract, stack *Stack, mem *Memory,
|
||||||
}
|
}
|
||||||
|
|
||||||
func gasExpFrontier(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
|
func gasExpFrontier(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
|
||||||
expByteLen := uint64((stack.Back(2).BitLen() + 7) / 8)
|
expByteLen := uint64((stack.Back(1).BitLen() + 7) / 8)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
gas = expByteLen * params.ExpByteFrontier // no overflow check required. Max is 256 * ExpByte gas
|
gas = expByteLen * params.ExpByteFrontier // no overflow check required. Max is 256 * ExpByte gas
|
||||||
|
|
@ -358,7 +358,7 @@ func gasExpFrontier(evm *EVM, contract *Contract, stack *Stack, mem *Memory, mem
|
||||||
}
|
}
|
||||||
|
|
||||||
func gasExpEIP158(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
|
func gasExpEIP158(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
|
||||||
expByteLen := uint64((stack.Back(2).BitLen() + 7) / 8)
|
expByteLen := uint64((stack.Back(1).BitLen() + 7) / 8)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
gas = expByteLen * params.ExpByteEIP158 // no overflow check required. Max is 256 * ExpByte gas
|
gas = expByteLen * params.ExpByteEIP158 // no overflow check required. Max is 256 * ExpByte gas
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import (
|
||||||
|
|
||||||
var stackPool = sync.Pool{
|
var stackPool = sync.Pool{
|
||||||
New: func() interface{} {
|
New: func() interface{} {
|
||||||
return &Stack{data: make([]uint256.Int, 0, 16)}
|
return &Stack{data: make([]uint256.Int, 0, 16), size: 0}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -33,6 +33,7 @@ var stackPool = sync.Pool{
|
||||||
// initialized objects.
|
// initialized objects.
|
||||||
type Stack struct {
|
type Stack struct {
|
||||||
data []uint256.Int
|
data []uint256.Int
|
||||||
|
size int
|
||||||
}
|
}
|
||||||
|
|
||||||
func newstack() *Stack {
|
func newstack() *Stack {
|
||||||
|
|
@ -41,27 +42,33 @@ func newstack() *Stack {
|
||||||
|
|
||||||
func returnStack(s *Stack) {
|
func returnStack(s *Stack) {
|
||||||
s.data = s.data[:0]
|
s.data = s.data[:0]
|
||||||
|
s.size = 0
|
||||||
stackPool.Put(s)
|
stackPool.Put(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Data returns the underlying uint256.Int array.
|
// Data returns the underlying uint256.Int array.
|
||||||
func (st *Stack) Data() []uint256.Int {
|
func (st *Stack) Data() []uint256.Int {
|
||||||
return st.data
|
return st.data[0:st.size]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *Stack) push(d *uint256.Int) {
|
func (st *Stack) push(d *uint256.Int) {
|
||||||
// NOTE push limit (1024) is checked in baseCheck
|
// NOTE push limit (1024) is checked in baseCheck
|
||||||
|
if st.size == len(st.data) {
|
||||||
st.data = append(st.data, *d)
|
st.data = append(st.data, *d)
|
||||||
|
} else {
|
||||||
|
st.data[st.size] = *d
|
||||||
|
}
|
||||||
|
st.size++
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *Stack) pop() (ret uint256.Int) {
|
func (st *Stack) pop() (ret uint256.Int) {
|
||||||
ret = st.data[len(st.data)-1]
|
ret = st.data[st.size-1]
|
||||||
st.data = st.data[:len(st.data)-1]
|
st.size--
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *Stack) len() int {
|
func (st *Stack) len() int {
|
||||||
return len(st.data)
|
return st.size
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *Stack) swap1() {
|
func (st *Stack) swap1() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue