Skip to content

Commit 302b444

Browse files
committed
Save some work (and potentially memory) during the final string concatenation.
1 parent 17a5ef3 commit 302b444

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/QAST/PIRT.nqp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,22 @@ class PIRT::Sub is PIRT::Node {
217217
}
218218
219219
method pir() {
220+
my @parts;
221+
self.collect_sub_pir_into(@parts);
222+
nqp::join("\n", @parts)
223+
}
224+
225+
method collect_sub_pir_into(@result) {
220226
# If we don't already have the sub body, then close the sub now.
221227
unless $!cached_pir {
222228
self.close_sub();
223229
}
224230
225-
# Our PIR is ourselve plus the PIR of any nested blocks.
226-
my @parts := [$!cached_pir];
231+
# Add our PIR followed by that of any nested blocks.
232+
@result.push($!cached_pir);
227233
for @!nested_blocks {
228-
nqp::push(@parts, $_.pir());
234+
$_.collect_sub_pir_into(@result);
229235
}
230-
nqp::join("\n", @parts)
231236
}
232237
}
233238

0 commit comments

Comments
 (0)