mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +00:00
parent
70755237e7
commit
20e6a3ef9d
2 changed files with 14 additions and 3 deletions
|
|
@ -57,10 +57,14 @@ func (m *Memory) Set32(offset uint64, val *uint256.Int) {
|
||||||
val.PutUint256(m.store[offset:])
|
val.PutUint256(m.store[offset:])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resize resizes the memory to size
|
// Resize grows the memory to the requested size.
|
||||||
func (m *Memory) Resize(size uint64) {
|
func (m *Memory) Resize(size uint64) {
|
||||||
if uint64(m.Len()) < size {
|
if uint64(len(m.store)) < 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(len(m.store)))...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,3 +67,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