new minor language feature: .noSideEffect blocks like .gcsafe blocks
This commit is contained in:
parent
93cf0ef52e
commit
413580bc04
7 changed files with 30 additions and 12 deletions
|
|
@ -82,7 +82,7 @@ type
|
|||
cap: int
|
||||
region: Allocator
|
||||
|
||||
proc newSeqPayload(cap, elemSize: int): pointer {.compilerRtl.} =
|
||||
proc newSeqPayload(cap, elemSize: int): pointer {.compilerRtl, noSideEffect.} =
|
||||
# we have to use type erasure here as Nim does not support generic
|
||||
# compilerProcs. Oh well, this will all be inlined anyway.
|
||||
if cap <= 0:
|
||||
|
|
@ -94,7 +94,8 @@ proc newSeqPayload(cap, elemSize: int): pointer {.compilerRtl.} =
|
|||
else:
|
||||
result = nil
|
||||
|
||||
proc prepareSeqAdd(len: int; p: pointer; addlen, elemSize: int): pointer {.compilerRtl.} =
|
||||
proc prepareSeqAdd(len: int; p: pointer; addlen, elemSize: int): pointer {.
|
||||
compilerRtl, noSideEffect.} =
|
||||
if len+addlen <= len:
|
||||
result = p
|
||||
elif p == nil:
|
||||
|
|
@ -128,7 +129,7 @@ proc grow*[T](x: var seq[T]; newLen: Natural; value: T) =
|
|||
xu.p = cast[typeof(xu.p)](prepareSeqAdd(oldLen, xu.p, newLen - oldLen, sizeof(T)))
|
||||
xu.len = newLen
|
||||
for i in oldLen .. newLen-1:
|
||||
x.data[i] = value
|
||||
xu.p.data[i] = value
|
||||
|
||||
proc setLen[T](s: var seq[T], newlen: Natural) =
|
||||
if newlen < s.len:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue