summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lib/system/strs_v2.nim3
-rw-r--r--tests/destructor/tgcdestructors.nim2
2 files changed, 2 insertions, 3 deletions
diff --git a/lib/system/strs_v2.nim b/lib/system/strs_v2.nim
index 3beb14382..aa644522f 100644
--- a/lib/system/strs_v2.nim
+++ b/lib/system/strs_v2.nim
@@ -107,8 +107,7 @@ proc mnewString(len: int): NimStringV2 {.compilerproc.} =
 
 proc setLengthStrV2(s: var NimStringV2, newLen: int) {.compilerRtl.} =
   if newLen == 0:
-    frees(s)
-    s.p = nil
+    discard "do not free the buffer here, pattern 's.setLen 0' is common for avoiding allocations"
   else:
     if newLen > s.len or isLiteral(s):
       prepareAdd(s, newLen - s.len)
diff --git a/tests/destructor/tgcdestructors.nim b/tests/destructor/tgcdestructors.nim
index e089aedd1..61d296d2e 100644
--- a/tests/destructor/tgcdestructors.nim
+++ b/tests/destructor/tgcdestructors.nim
@@ -10,7 +10,7 @@ a: @[4, 2, 3]
 0
 30
 true
-(allocCount: 40, deallocCount: 40)'''
+(allocCount: 36, deallocCount: 36)'''
 """
 
 include system / ansi_c