summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorBrent Pedersen <bpederse@gmail.com>2017-12-07 12:25:39 -0700
committerVarriount <Varriount@users.noreply.github.com>2017-12-07 14:25:39 -0500
commite016c9253e7b02ad4781452067dad980c677f61e (patch)
tree917b5c738fa4f461fc55e1a9124c8f711957bbb6 /lib
parentc7ba4d91a34882e94969595ba70763f9f642423c (diff)
downloadNim-e016c9253e7b02ad4781452067dad980c677f61e.tar.gz
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/system/sysstr.nim11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/system/sysstr.nim b/lib/system/sysstr.nim
index 3f8e0eff0..56b8ade97 100644
--- a/lib/system/sysstr.nim
+++ b/lib/system/sysstr.nim
@@ -259,7 +259,7 @@ proc incrSeqV2(seq: PGenericSeq, elemSize: int): PGenericSeq {.compilerProc.} =
     result.reserved = r
 
 proc setLengthSeq(seq: PGenericSeq, elemSize, newLen: int): PGenericSeq {.
-    compilerRtl.} =
+    compilerRtl, inl.} =
   result = seq
   if result.space < newLen:
     let r = max(resize(result.space), newLen)
@@ -282,10 +282,11 @@ proc setLengthSeq(seq: PGenericSeq, elemSize, newLen: int): PGenericSeq {.
             doDecRef(gch.tempStack.d[i], LocalHeap, MaybeCyclic)
           gch.tempStack.len = len0
       else:
-        for i in newLen..result.len-1:
-          forAllChildrenAux(cast[pointer](cast[ByteAddress](result) +%
-                            GenericSeqSize +% (i*%elemSize)),
-                            extGetCellType(result).base, waZctDecRef)
+        if ntfNoRefs notin extGetCellType(result).base.flags:
+          for i in newLen..result.len-1:
+            forAllChildrenAux(cast[pointer](cast[ByteAddress](result) +%
+                              GenericSeqSize +% (i*%elemSize)),
+                              extGetCellType(result).base, waZctDecRef)
 
     # XXX: zeroing out the memory can still result in crashes if a wiped-out
     # cell is aliased by another pointer (ie proc parameter or a let variable).