Skip to content

Commit

Permalink
evm: prealloc zeroes for Resize() (erigontech#6624)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored Mar 1, 2023
1 parent cf9ee42 commit 031292c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions core/vm/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,20 @@ func (m *Memory) Set32(offset uint64, val *uint256.Int) {
val.WriteToSlice(m.store[offset:])
}

// zeroes - pre-allocated zeroes for Resize()
var zeroes = make([]byte, 4*4096)

// Resize resizes the memory to size
func (m *Memory) Resize(size uint64) {
if uint64(m.Len()) < size {
m.store = append(m.store, make([]byte, size-uint64(m.Len()))...)
l := int(size) - m.Len()
if l <= 0 {
return
}
if l >= len(zeroes) {
m.store = append(m.store, make([]byte, l)...)
return
}
m.store = append(m.store, zeroes[:l]...)
}

// GetCopy returns offset + size as a new slice
Expand Down

0 comments on commit 031292c

Please sign in to comment.