runtime: Log, DateTime.format, Input.text, Path, Mime, Fs, Os and Text keep nothing per call
Found by reading every builtin (Os.platform's 8 KB per call started it). Log builds its line only at or above the threshold and frees it; DateTime.format folds through + so its pieces go; Input.text encodes into one buffer; Path/Mime/Fs/Os free their temporaries on every path; string results of Text/Path/Mime/DateTime/Os dirs are fresh and Text frees a fresh argument. Reseeded. runtime_temps.ludic: 19.8 MB -> 0 over 20,000 rounds, 64 KB -> 0 over 200 of file work; clean under MallocScribble. string_temps still 0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
404ee2ee3b
commit
254097657e
11 changed files with 38168 additions and 37714 deletions
|
|
@ -130,10 +130,6 @@ function is_datetime_ns(meth: pointer) -> bool {
|
|||
return false
|
||||
}
|
||||
|
||||
# concat two runtime string codes -> a fresh string code
|
||||
function dt_concat(a: pointer, b: pointer) -> pointer {
|
||||
return emit_bind(`call ptr @lp_str_concat(ptr {a}, ptr {b})`)
|
||||
}
|
||||
|
||||
# does the pattern have token `tok` (length tlen) starting at index i?
|
||||
function dt_tok_at(pat: pointer, n: int, i: int, tok: pointer, tlen: int) -> bool {
|
||||
|
|
@ -167,7 +163,9 @@ function emit_datetime_format(e: Node) -> Val {
|
|||
let mi = emit_bind(`sdiv i32 {m3}, 60`)
|
||||
let ss = emit_bind(`srem i32 {sod}, 60`)
|
||||
let yy = emit_bind(`srem i32 {yv}, 100`)
|
||||
var acc = emit_str_const("")
|
||||
# joined as ordinary text: each field's digits and each piece so far are freed once the next join
|
||||
# has copied them, so only the answer is left (every one of them was once kept)
|
||||
var acc = val(emit_str_const(""), "string")
|
||||
let lit = buf_new()
|
||||
var i = 0
|
||||
while i < n {
|
||||
|
|
@ -182,16 +180,16 @@ function emit_datetime_format(e: Node) -> Val {
|
|||
if (field == null) { buf_putc(lit, pat[i]); i += 1 }
|
||||
else {
|
||||
let ls = buf_str(lit)
|
||||
if len(ls) > 0 { acc = dt_concat(acc, emit_str_const(ls)) }
|
||||
let piece = emit_bind(`call ptr @lp_dt_pad0(i32 {field}, i32 {width})`)
|
||||
acc = dt_concat(acc, piece)
|
||||
if len(ls) > 0 { acc = emit_str_op("+", acc, val(emit_str_const(ls), "string")) }
|
||||
let piece = fresh_val(emit_bind(`call ptr @lp_dt_pad0(i32 {field}, i32 {width})`), "string")
|
||||
acc = emit_str_op("+", acc, piece)
|
||||
lit.len = 0 # start a fresh literal run
|
||||
i += tlen
|
||||
}
|
||||
}
|
||||
let tail = buf_str(lit)
|
||||
if len(tail) > 0 { acc = dt_concat(acc, emit_str_const(tail)) }
|
||||
return val(acc, "string")
|
||||
if len(tail) > 0 { acc = emit_str_op("+", acc, val(emit_str_const(tail), "string")) }
|
||||
return acc
|
||||
}
|
||||
|
||||
# DateTime.parse(s, "pattern") -> DateTime. The pattern MUST be a string literal;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue