Skip to content

Commit

Permalink
fixes regression #20746; remove string copies for ORC booted compiler (
Browse files Browse the repository at this point in the history
…#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
  • Loading branch information
ringabout committed Nov 7, 2022
1 parent 66b0c84 commit 600b3a9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/vm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions tests/vm/t20746.nim
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 600b3a9

Please sign in to comment.