mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
core/vm: refactor memory resize
This commit is contained in:
parent
243407a3aa
commit
7e30dfb18c
2 changed files with 12 additions and 2 deletions
|
|
@ -76,10 +76,13 @@ func (m *Memory) Set32(offset uint64, val *uint256.Int) {
|
|||
val.PutUint256(m.store[offset:])
|
||||
}
|
||||
|
||||
// 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()))...)
|
||||
if uint64(cap(m.store)) > size {
|
||||
m.store = m.store[:size]
|
||||
} else {
|
||||
m.store = append(m.store, make([]byte, size-uint64(m.Len()))...)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -83,3 +83,10 @@ func TestMemoryCopy(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkResize(b *testing.B) {
|
||||
memory := NewMemory()
|
||||
for i := range b.N {
|
||||
memory.Resize(uint64(i))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue