optimize the new nimPrepareStrMutationV2 with inlining (#14969)
This commit is contained in:
parent
124feb2af8
commit
6cc0061a72
1 changed files with 9 additions and 6 deletions
|
|
@ -132,10 +132,13 @@ proc nimAsgnStrV2(a: var NimStringV2, b: NimStringV2) {.compilerRtl.} =
|
||||||
a.len = b.len
|
a.len = b.len
|
||||||
copyMem(unsafeAddr a.p.data[0], unsafeAddr b.p.data[0], b.len+1)
|
copyMem(unsafeAddr a.p.data[0], unsafeAddr b.p.data[0], b.len+1)
|
||||||
|
|
||||||
proc nimPrepareStrMutationV2(s: var NimStringV2) {.compilerRtl.} =
|
proc nimPrepareStrMutationImpl(s: var NimStringV2) =
|
||||||
if s.p != nil and (s.p.cap and strlitFlag) == strlitFlag:
|
|
||||||
let oldP = s.p
|
let oldP = s.p
|
||||||
# can't mutate a literal, so we need a fresh copy here:
|
# can't mutate a literal, so we need a fresh copy here:
|
||||||
s.p = cast[ptr NimStrPayload](allocShared0(contentSize(s.len)))
|
s.p = cast[ptr NimStrPayload](allocShared0(contentSize(s.len)))
|
||||||
s.p.cap = s.len
|
s.p.cap = s.len
|
||||||
copyMem(unsafeAddr s.p.data[0], unsafeAddr oldP.data[0], s.len+1)
|
copyMem(unsafeAddr s.p.data[0], unsafeAddr oldP.data[0], s.len+1)
|
||||||
|
|
||||||
|
proc nimPrepareStrMutationV2(s: var NimStringV2) {.compilerRtl, inline.} =
|
||||||
|
if s.p != nil and (s.p.cap and strlitFlag) == strlitFlag:
|
||||||
|
nimPrepareStrMutationImpl(s)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue