ARC/ORC: optimize s.setLen(0) to match the old runtime's behaviour (#14423)

This commit is contained in:
Andreas Rumpf 2020-05-21 22:38:13 +02:00 • committed by GitHub
commit 3eaa870c0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 3 deletions

View file

@ -107,8 +107,7 @@ proc mnewString(len: int): NimStringV2 {.compilerproc.} =
proc setLengthStrV2(s: var NimStringV2, newLen: int) {.compilerRtl.} = proc setLengthStrV2(s: var NimStringV2, newLen: int) {.compilerRtl.} =
if newLen == 0: if newLen == 0:
frees(s) discard "do not free the buffer here, pattern 's.setLen 0' is common for avoiding allocations"
s.p = nil
else: else:
if newLen > s.len or isLiteral(s): if newLen > s.len or isLiteral(s):
prepareAdd(s, newLen - s.len) prepareAdd(s, newLen - s.len)

View file

@ -10,7 +10,7 @@ a: @[4, 2, 3]
0 0
30 30
true true
(allocCount: 40, deallocCount: 40)''' (allocCount: 36, deallocCount: 36)'''
""" """
include system / ansi_c include system / ansi_c