compiler: a string slice is a fresh temporary too
s[a .. b] is always a copy, so it is freed once a +, a comparison or print has read it. Reseeded. string_temps.ludic adds a slice compared and a slice concatenated each round (960 KB over 20,000 before, 0 after) and a kept slice read after its +. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
174a32c285
commit
328dee77c8
5 changed files with 940 additions and 861 deletions
|
|
@ -1056,7 +1056,8 @@ function emit_expr(e: Node) -> Val {
|
|||
let lo = emit_expr(e.b)
|
||||
let hi = emit_expr(e.c)
|
||||
g_uses_strslice = true
|
||||
return val(emit_bind(`call ptr @lp_str_slice(ptr {base.code}, i32 {lo.code}, i32 {hi.code})`), "string")
|
||||
# a copy, so it is fresh: `s[0 .. n - 4] + ".dds"` and `s[a .. b] == "x"` free it once read
|
||||
return fresh_val(emit_bind(`call ptr @lp_str_slice(ptr {base.code}, i32 {lo.code}, i32 {hi.code})`), "string")
|
||||
}
|
||||
if e.kind == E_STR { return val(emit_str_const(e.s), "string") }
|
||||
if e.kind == E_NEW {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue