summary refs log tree commit diff stats
path: root/lib/system
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2020-01-26 10:50:21 +0100
committerAndreas Rumpf <rumpf_a@web.de>2020-01-26 13:43:02 +0100
commita10cc18247cb576aa409e9056ed99f23539d14f9 (patch)
tree8ad1a8ac55ccb34b9438bbfb57476fcad01d7261 /lib/system
parentab35f07e774c3faaee3708479523e66614eb3aa6 (diff)
downloadNim-a10cc18247cb576aa409e9056ed99f23539d14f9.tar.gz
ARC: optimize complete object constructors to use nimNewObjUninit
Diffstat (limited to 'lib/system')
-rw-r--r--lib/system/refs_v2.nim17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/system/refs_v2.nim b/lib/system/refs_v2.nim
index 5ac0f0b8e..f6f3ba01c 100644
--- a/lib/system/refs_v2.nim
+++ b/lib/system/refs_v2.nim
@@ -72,6 +72,23 @@ proc nimNewObj(size: int): pointer {.compilerRtl.} =
   when traceCollector:
     cprintf("[Allocated] %p\n", result -! sizeof(RefHeader))
 
+proc nimNewObjUninit(size: int): pointer {.compilerRtl.} =
+  # Same as 'newNewObj' but do not initialize the memory to zero.
+  # The codegen proved for us that this is not necessary.
+  let s = size + sizeof(RefHeader)
+  when defined(nimscript):
+    discard
+  elif defined(useMalloc):
+    var orig = cast[ptr RefHeader](c_malloc(cuint s))
+  elif compileOption("threads"):
+    var orig = cast[ptr RefHeader](allocShared(s))
+  else:
+    var orig = cast[ptr RefHeader](alloc(s))
+  orig.rc = 0
+  result = orig +! sizeof(RefHeader)
+  when traceCollector:
+    cprintf("[Allocated] %p\n", result -! sizeof(RefHeader))
+
 proc nimDecWeakRef(p: pointer) {.compilerRtl, inl.} =
   dec head(p).rc, rcIncrement