destructors: we are cooking now
This commit is contained in:
parent
fab75fbaf1
commit
6e6a9a721f
9 changed files with 73 additions and 43 deletions
|
|
@ -177,17 +177,15 @@ proc nimAsgnStrV2(a: var NimStringV2, b: NimStringV2) {.compilerRtl.} =
|
|||
frees(a)
|
||||
a.len = b.len
|
||||
a.p = b.p
|
||||
elif isLiteral(a) or a.p.cap < b.len:
|
||||
let allocator = if a.p != nil and a.p.allocator != nil: a.p.allocator else: getLocalAllocator()
|
||||
# we have to allocate the 'cap' here, consider
|
||||
# 'let y = newStringOfCap(); var x = y'
|
||||
# on the other hand... These get turned into moves now.
|
||||
a.p = cast[ptr NimStrPayload](allocator.alloc(allocator, contentSize(b.len)))
|
||||
a.p.allocator = allocator
|
||||
a.p.cap = b.len
|
||||
a.len = b.len
|
||||
copyMem(unsafeAddr a.p.data[0], unsafeAddr b.p.data[0], b.len+1)
|
||||
else:
|
||||
if isLiteral(a) or a.p.cap < b.len:
|
||||
let allocator = if a.p != nil and a.p.allocator != nil: a.p.allocator else: getLocalAllocator()
|
||||
# we have to allocate the 'cap' here, consider
|
||||
# 'let y = newStringOfCap(); var x = y'
|
||||
# on the other hand... These get turned into moves now.
|
||||
frees(a)
|
||||
a.p = cast[ptr NimStrPayload](allocator.alloc(allocator, contentSize(b.len)))
|
||||
a.p.allocator = allocator
|
||||
a.p.cap = b.len
|
||||
a.len = b.len
|
||||
# reuse the storage we already have:
|
||||
copyMem(unsafeAddr a.p.data[0], unsafeAddr b.p.data[0], b.len+1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue