summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAmjad Ben Hedhili <amjadhedhili@outlook.com>2023-09-25 06:19:09 +0100
committerGitHub <noreply@github.com>2023-09-25 07:19:09 +0200
commitf0bf94e5311e851cba4370c2310c0be66e535a27 (patch)
tree819344abab6a70211446129a9a657daad6ef45af
parent584010196856e4c357996696e932ba0ffbc61f84 (diff)
downloadNim-f0bf94e5311e851cba4370c2310c0be66e535a27.tar.gz
Make `newStringUninit` available in the VM [backport] (#22748)
It's equivalent to `newString`.
-rw-r--r--lib/system.nim21
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/system.nim b/lib/system.nim
index 64412b9b3..8e16d17d4 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -1637,16 +1637,19 @@ when not defined(js):
     ##
     ## This procedure exists only for optimization purposes;
     ## the same effect can be achieved with the `&` operator or with `add`.
-    result = newStringOfCap(len)
-    when defined(nimSeqsV2):
-      let s = cast[ptr NimStringV2](addr result)
-      if len > 0:
-        s.len = len
-        s.p.data[len] = '\0'
+    when nimvm:
+      result = newString(len)
     else:
-      let s = cast[NimString](result)
-      s.len = len
-      s.data[len] = '\0'
+      result = newStringOfCap(len)
+      when defined(nimSeqsV2):
+        let s = cast[ptr NimStringV2](addr result)
+        if len > 0:
+          s.len = len
+          s.p.data[len] = '\0'
+      else:
+        let s = cast[NimString](result)
+        s.len = len
+        s.data[len] = '\0'
 else:
   proc newStringUninit*(len: Natural): string {.
     magic: "NewString", importc: "mnewString", noSideEffect.}