mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-19 03:10:48 +00:00
core/vm: improve memory resize
This commit is contained in:
parent
aa457eda4b
commit
3f5229d33b
1 changed files with 10 additions and 1 deletions
|
|
@ -83,7 +83,16 @@ func (m *Memory) Resize(size uint64) {
|
|||
if uint64(cap(m.store)) >= size {
|
||||
m.store = m.store[:size]
|
||||
} else {
|
||||
m.store = append(m.store, make([]byte, size-uint64(len(m.store)))...)
|
||||
newCap := uint64(cap(m.store))
|
||||
if newCap == 0 {
|
||||
newCap = 1
|
||||
}
|
||||
for newCap < size {
|
||||
newCap *= 2
|
||||
}
|
||||
newStore := make([]byte, size, newCap)
|
||||
copy(newStore, m.store)
|
||||
m.store = newStore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue