diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2022-11-07 21:36:43 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-07 14:36:43 +0100 |
commit | 600b3a91abbe7dede5abd9744e02fc48089ee34d (patch) | |
tree | 6c16bd3a18a700631f48626aa9fd1adc37f0ddb5 | |
parent | 66b0c843c34dba2a8f28e1c02ff996516a3c5c2a (diff) | |
download | Nim-600b3a91abbe7dede5abd9744e02fc48089ee34d.tar.gz |
fixes regression #20746; remove string copies for ORC booted compiler (#20776)
* fixes #20746; remove string copies for ORC booted compiler * add a test case * use `cursor` thanks to @beef331 * for old compilers * change file extension * change test cases
-rw-r--r-- | compiler/vm.nim | 4 | ||||
-rw-r--r-- | tests/vm/t20746.nim | 13 |
2 files changed, 16 insertions, 1 deletions
diff --git a/compiler/vm.nim b/compiler/vm.nim index 1a41ce8a1..99d8c4d41 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -32,6 +32,8 @@ const when hasFFI: import evalffi +when not defined(nimHasCursor): + {.pragma: cursor.} proc stackTraceAux(c: PCtx; x: PStackFrame; pc: int; recursionLimit=100) = if x != nil: @@ -787,7 +789,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = of opcLdStrIdx: decodeBC(rkInt) let idx = regs[rc].intVal.int - let s = regs[rb].node.strVal + let s {.cursor.} = regs[rb].node.strVal if idx <% s.len: regs[ra].intVal = s[idx].ord else: diff --git a/tests/vm/t20746.nim b/tests/vm/t20746.nim new file mode 100644 index 000000000..bfad269ef --- /dev/null +++ b/tests/vm/t20746.nim @@ -0,0 +1,13 @@ +discard """ + timeout: 10 + joinable: false + output: "fine" +""" + +func addString(): string = + let x = newString(1000000) + for i in 0..<1000000: + discard x[i] + +const translationTable = addString() +echo "fine" |