optimize setLen (#6816)
inline the call to setLengthSeq and avoid decref for types if ntfNoRefs closes #6721 and speeds setLen when newLen < len for non reference types.
This commit is contained in:
parent
c7ba4d91a3
commit
e016c9253e
1 changed files with 6 additions and 5 deletions
|
|
@ -259,7 +259,7 @@ proc incrSeqV2(seq: PGenericSeq, elemSize: int): PGenericSeq {.compilerProc.} =
|
||||||
result.reserved = r
|
result.reserved = r
|
||||||
|
|
||||||
proc setLengthSeq(seq: PGenericSeq, elemSize, newLen: int): PGenericSeq {.
|
proc setLengthSeq(seq: PGenericSeq, elemSize, newLen: int): PGenericSeq {.
|
||||||
compilerRtl.} =
|
compilerRtl, inl.} =
|
||||||
result = seq
|
result = seq
|
||||||
if result.space < newLen:
|
if result.space < newLen:
|
||||||
let r = max(resize(result.space), newLen)
|
let r = max(resize(result.space), newLen)
|
||||||
|
|
@ -282,6 +282,7 @@ proc setLengthSeq(seq: PGenericSeq, elemSize, newLen: int): PGenericSeq {.
|
||||||
doDecRef(gch.tempStack.d[i], LocalHeap, MaybeCyclic)
|
doDecRef(gch.tempStack.d[i], LocalHeap, MaybeCyclic)
|
||||||
gch.tempStack.len = len0
|
gch.tempStack.len = len0
|
||||||
else:
|
else:
|
||||||
|
if ntfNoRefs notin extGetCellType(result).base.flags:
|
||||||
for i in newLen..result.len-1:
|
for i in newLen..result.len-1:
|
||||||
forAllChildrenAux(cast[pointer](cast[ByteAddress](result) +%
|
forAllChildrenAux(cast[pointer](cast[ByteAddress](result) +%
|
||||||
GenericSeqSize +% (i*%elemSize)),
|
GenericSeqSize +% (i*%elemSize)),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue