Skip to content

Commit f0bca91

Browse files
committed
perf(builtins): the list every list operation works on is borrowed, as is the list joined
Only the box that carries a list into a dynamic slot keeps it, so a list whose last use is any other list operation or a join is released there instead of being left to the collector. git-bug: 3b55803520d2f3bf52cd49c690ea187c51fbdee7a95cdf2374db346a9fd5b04c
1 parent 296158d commit f0bca91

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎crates/zyntax_builtins/src/lists.rs‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,10 @@ pub(crate) fn declarations(policy: &Policy, list_type: TypeId) -> Vec<Decl> {
268268

269269
fn kind_declarations(k: &KindOps) -> Vec<Decl> {
270270
let name = |op: &str| format!("zb_list_{op}_{}", k.kind.suffix());
271-
let xs = local("xs", k.list.clone());
271+
// The list every operation works on is read or edited in place and
272+
// never kept, except by the box that carries it into a dynamic slot.
273+
let xs = borrowed("xs", k.list.clone());
274+
let carried = local("xs", k.list.clone());
272275
// The second list of a two-list operation is only read: extended
273276
// from, concatenated, compared, assigned from.
274277
let ys = borrowed("ys", k.list.clone());
@@ -1164,11 +1167,11 @@ fn kind_declarations(k: &KindOps) -> Vec<Decl> {
11641167
));
11651168
d.push(define(
11661169
&name("box"),
1167-
&[&xs],
1170+
&[&carried],
11681171
any(),
11691172
vec![ret(call(
11701173
&format!("zb_box_list_raw_{}", k.kind.suffix()),
1171-
vec![xs.e(), int32(k.kind.list_tag() as i32)],
1174+
vec![carried.e(), int32(k.kind.list_tag() as i32)],
11721175
any(),
11731176
))],
11741177
));
@@ -1549,7 +1552,7 @@ fn shared(_policy: &Policy, list_type: TypeId) -> Vec<Decl> {
15491552
));
15501553
// One allocation for the whole result: the plugin reads the parts
15511554
// straight out of the list's storage.
1552-
let parts = local("parts", strs.clone());
1555+
let parts = borrowed("parts", strs.clone());
15531556
d.push(extern_fn(
15541557
"zb_str_join_raw",
15551558
&[("data", i64()), ("n", i64()), ("sep", string())],

0 commit comments

Comments
 (0)