diff options
Diffstat (limited to 'lib/core/seqs.nim')
-rw-r--r-- | lib/core/seqs.nim | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/core/seqs.nim b/lib/core/seqs.nim index c62a05904..a41ef10ab 100644 --- a/lib/core/seqs.nim +++ b/lib/core/seqs.nim @@ -85,7 +85,7 @@ type proc newSeqPayload(cap, elemSize: int): pointer {.compilerRtl.} = # 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: + if cap > 0: let region = getLocalAllocator() var p = cast[ptr PayloadBase](region.alloc(region, cap * elemSize + sizeof(int) + sizeof(Allocator))) p.region = region @@ -126,18 +126,19 @@ proc grow*[T](x: var seq[T]; newLen: Natural; value: T) = let oldLen = x.len if newLen <= oldLen: return var xu = cast[ptr NimSeqV2[T]](addr x) - - xu.p = cast[typeof(xu.p)](prepareSeqAdd(oldLen, xu.p, newLen - oldLen, sizeof(T))) + if xu.p == nil or xu.p.cap < newLen: + xu.p = cast[typeof(xu.p)](prepareSeqAdd(oldLen, xu.p, newLen - oldLen, sizeof(T))) xu.len = newLen for i in oldLen .. newLen-1: xu.p.data[i] = value proc setLen[T](s: var seq[T], newlen: Natural) = - if newlen < s.len: - shrink(s, newLen) - else: - var v: T # get the default value of 'v' - grow(s, newLen, v) + {.noSideEffect.}: + if newlen < s.len: + shrink(s, newLen) + else: + var v: T # get the default value of 'v' + grow(s, newLen, v) when false: proc resize[T](s: var NimSeqV2[T]) = |