optimize EVM memory extend
This commit is contained in:
parent
2fc349feb9
commit
742759e607
|
@ -28,11 +28,10 @@ proc len*(memory: Memory): int =
|
|||
proc extend*(memory: var Memory; startPos: Natural; size: Natural) =
|
||||
if size == 0:
|
||||
return
|
||||
var newSize = ceil32(startPos + size)
|
||||
let newSize = ceil32(startPos + size)
|
||||
if newSize <= len(memory):
|
||||
return
|
||||
var sizeToExtend = newSize - len(memory)
|
||||
memory.bytes = memory.bytes.concat(repeat(0.byte, sizeToExtend))
|
||||
memory.bytes.setLen(newSize)
|
||||
|
||||
proc newMemory*(size: Natural): Memory =
|
||||
result = newMemory()
|
||||
|
@ -51,9 +50,6 @@ proc write*(memory: var Memory, startPos: Natural, value: openArray[byte]) =
|
|||
let size = value.len
|
||||
if size == 0:
|
||||
return
|
||||
validateLte(startPos + size, memory.len)
|
||||
if memory.len < startPos + size:
|
||||
memory.bytes = memory.bytes.concat(repeat(0.byte, memory.len - (startPos + size))) # TODO: better logarithmic scaling?
|
||||
|
||||
validateLte(startPos + size, memory.len)
|
||||
for z, b in value:
|
||||
memory.bytes[z + startPos] = b
|
||||
|
|
|
@ -34,6 +34,11 @@ proc validateLt*(value: UInt256 | int, maximum: int, title: string = "Value") =
|
|||
raise newException(ValidationError,
|
||||
&"{title} {value} is not less than {maximum}")
|
||||
|
||||
proc validateLte*(value: int, maximum: int, title: string = "Value") =
|
||||
if value > maximum:
|
||||
raise newException(ValidationError,
|
||||
&"{title} {value} is not less or equal to {maximum}")
|
||||
|
||||
proc validateStackItem*(value: string) =
|
||||
if value.len > 32:
|
||||
raise newException(ValidationError,
|
||||
|
|
Loading…
Reference in New Issue