some progress on --gc:destructors
This commit is contained in:
parent
413580bc04
commit
8990764709
1 changed files with 18 additions and 17 deletions
|
|
@ -82,7 +82,7 @@ type
|
||||||
cap: int
|
cap: int
|
||||||
region: Allocator
|
region: Allocator
|
||||||
|
|
||||||
proc newSeqPayload(cap, elemSize: int): pointer {.compilerRtl, noSideEffect.} =
|
proc newSeqPayload(cap, elemSize: int): pointer {.compilerRtl.} =
|
||||||
# we have to use type erasure here as Nim does not support generic
|
# we have to use type erasure here as Nim does not support generic
|
||||||
# compilerProcs. Oh well, this will all be inlined anyway.
|
# compilerProcs. Oh well, this will all be inlined anyway.
|
||||||
if cap <= 0:
|
if cap <= 0:
|
||||||
|
|
@ -96,22 +96,23 @@ proc newSeqPayload(cap, elemSize: int): pointer {.compilerRtl, noSideEffect.} =
|
||||||
|
|
||||||
proc prepareSeqAdd(len: int; p: pointer; addlen, elemSize: int): pointer {.
|
proc prepareSeqAdd(len: int; p: pointer; addlen, elemSize: int): pointer {.
|
||||||
compilerRtl, noSideEffect.} =
|
compilerRtl, noSideEffect.} =
|
||||||
if len+addlen <= len:
|
{.noSideEffect.}:
|
||||||
result = p
|
if len+addlen <= len:
|
||||||
elif p == nil:
|
result = p
|
||||||
result = newSeqPayload(len+addlen, elemSize)
|
elif p == nil:
|
||||||
else:
|
result = newSeqPayload(len+addlen, elemSize)
|
||||||
# Note: this means we cannot support things that have internal pointers as
|
else:
|
||||||
# they get reallocated here. This needs to be documented clearly.
|
# Note: this means we cannot support things that have internal pointers as
|
||||||
var p = cast[ptr PayloadBase](p)
|
# they get reallocated here. This needs to be documented clearly.
|
||||||
let region = if p.region == nil: getLocalAllocator() else: p.region
|
var p = cast[ptr PayloadBase](p)
|
||||||
let cap = max(resize(p.cap), len+addlen)
|
let region = if p.region == nil: getLocalAllocator() else: p.region
|
||||||
var q = cast[ptr PayloadBase](region.realloc(region, p,
|
let cap = max(resize(p.cap), len+addlen)
|
||||||
sizeof(int) + sizeof(Allocator) + elemSize * p.cap,
|
var q = cast[ptr PayloadBase](region.realloc(region, p,
|
||||||
sizeof(int) + sizeof(Allocator) + elemSize * cap))
|
sizeof(int) + sizeof(Allocator) + elemSize * p.cap,
|
||||||
q.region = region
|
sizeof(int) + sizeof(Allocator) + elemSize * cap))
|
||||||
q.cap = cap
|
q.region = region
|
||||||
result = q
|
q.cap = cap
|
||||||
|
result = q
|
||||||
|
|
||||||
proc shrink*[T](x: var seq[T]; newLen: Natural) =
|
proc shrink*[T](x: var seq[T]; newLen: Natural) =
|
||||||
sysAssert newLen <= x.len, "invalid newLen parameter for 'shrink'"
|
sysAssert newLen <= x.len, "invalid newLen parameter for 'shrink'"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue