fixes #7833; still to-do: fix setLen

This commit is contained in:
Araq 2018-07-30 23:27:01 +02:00
commit 53566f7165
4 changed files with 17 additions and 10 deletions

View file

@ -1092,17 +1092,20 @@ proc genSeqElemAppend(p: BProc, e: PNode, d: var TLoc) =
# seq = (typeof seq) incrSeq(&seq->Sup, sizeof(x)); # seq = (typeof seq) incrSeq(&seq->Sup, sizeof(x));
# seq->data[seq->len-1] = x; # seq->data[seq->len-1] = x;
let seqAppendPattern = if not p.module.compileToCpp: let seqAppendPattern = if not p.module.compileToCpp:
"$1 = ($2) #incrSeqV3(&($1)->Sup, $3);$n" "($2) #incrSeqV3(&($1)->Sup, $3)"
else: else:
"$1 = ($2) #incrSeqV3($1, $3);$n" "($2) #incrSeqV3($1, $3)"
var a, b, dest, tmpL: TLoc var a, b, dest, tmpL, call: TLoc
initLocExpr(p, e.sons[1], a) initLocExpr(p, e.sons[1], a)
initLocExpr(p, e.sons[2], b) initLocExpr(p, e.sons[2], b)
let seqType = skipTypes(e.sons[1].typ, {tyVar}) let seqType = skipTypes(e.sons[1].typ, {tyVar})
lineCg(p, cpsStmts, seqAppendPattern, [ initLoc(call, locCall, e, OnHeap)
rdLoc(a), call.r = ropecg(p.module, seqAppendPattern, [rdLoc(a),
getTypeDesc(p.module, e.sons[1].typ), getTypeDesc(p.module, e.sons[1].typ),
genTypeInfo(p.module, seqType, e.info)]) genTypeInfo(p.module, seqType, e.info)])
# emit the write barrier if required, but we can always move here, so
# use 'genRefAssign' for the seq.
genRefAssign(p, a, call, {})
#if bt != b.t: #if bt != b.t:
# echo "YES ", e.info, " new: ", typeToString(bt), " old: ", typeToString(b.t) # echo "YES ", e.info, " new: ", typeToString(bt), " old: ", typeToString(b.t)
initLoc(dest, locExpr, e.sons[2], OnHeap) initLoc(dest, locExpr, e.sons[2], OnHeap)

View file

@ -72,3 +72,4 @@ proc initDefines*(symbols: StringTableRef) =
defineSymbol("nimNoZeroTerminator") defineSymbol("nimNoZeroTerminator")
defineSymbol("nimNotNil") defineSymbol("nimNotNil")
defineSymbol("nimVmExportFixed") defineSymbol("nimVmExportFixed")
defineSymbol("nimIncrSeqV3")

View file

@ -548,7 +548,10 @@ proc growObj(old: pointer, newsize: int, gch: var GcHeap): pointer =
gcTrace(res, csAllocated) gcTrace(res, csAllocated)
track("growObj old", ol, 0) track("growObj old", ol, 0)
track("growObj new", res, newsize) track("growObj new", res, newsize)
when reallyDealloc: when defined(nimIncrSeqV3):
# since we steal the old seq's contents, we set the old length to 0.
cast[PGenericSeq](old).len = 0
elif reallyDealloc:
sysAssert(allocInv(gch.region), "growObj before dealloc") sysAssert(allocInv(gch.region), "growObj before dealloc")
if ol.refcount shr rcShift <=% 1: if ol.refcount shr rcShift <=% 1:
# free immediately to save space: # free immediately to save space:

View file

@ -14,11 +14,11 @@ proc handleRequest(query: string): StringTableRef =
let x = foo let x = foo
result = x() result = x()
const Limit = when compileOption("gc", "markAndSweep"): 5*1024*1024 else: 700_000 const Limit = 5*1024*1024
proc main = proc main =
var counter = 0 var counter = 0
for i in 0 .. 100_000: for i in 0 .. 10_000_000:
for k, v in handleRequest("nick=Elina2&type=activate"): for k, v in handleRequest("nick=Elina2&type=activate"):
inc counter inc counter
if counter mod 100 == 0: if counter mod 100 == 0: