summary refs log tree commit diff stats
path: root/lib/system/strs_v2.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/system/strs_v2.nim')
-rw-r--r--lib/system/strs_v2.nim7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/system/strs_v2.nim b/lib/system/strs_v2.nim
index fe117997b..b20457d51 100644
--- a/lib/system/strs_v2.nim
+++ b/lib/system/strs_v2.nim
@@ -168,3 +168,10 @@ proc nimPrepareStrMutationImpl(s: var NimStringV2) =
 proc nimPrepareStrMutationV2(s: var NimStringV2) {.compilerRtl, inline.} =
   if s.p != nil and (s.p.cap and strlitFlag) == strlitFlag:
     nimPrepareStrMutationImpl(s)
+
+proc prepareStrMutation*(s: var string) {.inline.} =
+  # string literals are "copy on write", so you need to call
+  # `prepareStrMutation` before modifying the strings.
+  {.cast(noSideEffect).}:
+    let s = unsafeAddr s
+    nimPrepareStrMutationV2(cast[ptr NimStringV2](s)[])