diff options
author | Araq <rumpf_a@web.de> | 2013-12-03 13:30:58 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2013-12-03 13:30:58 +0100 |
commit | 32d2327be025f62bd1b51a98322879cc7e8d218f (patch) | |
tree | 9d287450bc09d20a4fca7a7b9c387e4bb8f6b595 | |
parent | 5cb60ffbe0c3afde964467fc2ab99bc3bbd42968 (diff) | |
download | Nim-32d2327be025f62bd1b51a98322879cc7e8d218f.tar.gz |
don't use memset for temps unless necessary
-rw-r--r-- | compiler/cgen.nim | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 24d3c2923..ad9ade63c 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -370,14 +370,17 @@ proc resetLoc(p: BProc, loc: var TLoc) = # on the bytes following the m_type field? genObjectInit(p, cpsStmts, loc.t, loc, true) -proc constructLoc(p: BProc, loc: TLoc, section = cpsStmts) = +proc constructLoc(p: BProc, loc: TLoc, isTemp = false) = if not isComplexValueType(skipTypes(loc.t, abstractRange)): - linefmt(p, section, "$1 = 0;$n", rdLoc(loc)) + linefmt(p, cpsStmts, "$1 = 0;$n", rdLoc(loc)) else: - useStringh(p.module) - linefmt(p, section, "memset((void*)$1, 0, sizeof($2));$n", - addrLoc(loc), rdLoc(loc)) - genObjectInit(p, section, loc.t, loc, true) + if not isTemp or containsGarbageCollectedRef(loc.t): + # don't use memset for temporary values for performance if we can + # avoid it: + useStringh(p.module) + linefmt(p, cpsStmts, "memset((void*)$1, 0, sizeof($2));$n", + addrLoc(loc), rdLoc(loc)) + genObjectInit(p, cpsStmts, loc.t, loc, true) proc initLocalVar(p: BProc, v: PSym, immediateAsgn: bool) = if sfNoInit notin v.flags: @@ -403,7 +406,7 @@ proc getTemp(p: BProc, t: PType, result: var TLoc) = result.t = getUniqueType(t) result.s = OnStack result.flags = {} - constructLoc(p, result) + constructLoc(p, result, isTemp=true) proc keepAlive(p: BProc, toKeepAlive: TLoc) = when false: |