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) =
|
proc extend*(memory: var Memory; startPos: Natural; size: Natural) =
|
||||||
if size == 0:
|
if size == 0:
|
||||||
return
|
return
|
||||||
var newSize = ceil32(startPos + size)
|
let newSize = ceil32(startPos + size)
|
||||||
if newSize <= len(memory):
|
if newSize <= len(memory):
|
||||||
return
|
return
|
||||||
var sizeToExtend = newSize - len(memory)
|
memory.bytes.setLen(newSize)
|
||||||
memory.bytes = memory.bytes.concat(repeat(0.byte, sizeToExtend))
|
|
||||||
|
|
||||||
proc newMemory*(size: Natural): Memory =
|
proc newMemory*(size: Natural): Memory =
|
||||||
result = newMemory()
|
result = newMemory()
|
||||||
|
@ -52,8 +51,5 @@ proc write*(memory: var Memory, startPos: Natural, value: openArray[byte]) =
|
||||||
if size == 0:
|
if size == 0:
|
||||||
return
|
return
|
||||||
validateLte(startPos + size, memory.len)
|
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?
|
|
||||||
|
|
||||||
for z, b in value:
|
for z, b in value:
|
||||||
memory.bytes[z + startPos] = b
|
memory.bytes[z + startPos] = b
|
||||||
|
|
|
@ -34,6 +34,11 @@ proc validateLt*(value: UInt256 | int, maximum: int, title: string = "Value") =
|
||||||
raise newException(ValidationError,
|
raise newException(ValidationError,
|
||||||
&"{title} {value} is not less than {maximum}")
|
&"{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) =
|
proc validateStackItem*(value: string) =
|
||||||
if value.len > 32:
|
if value.len > 32:
|
||||||
raise newException(ValidationError,
|
raise newException(ValidationError,
|
||||||
|
|
Loading…
Reference in New Issue