Skip to content

Commit 2ffe8f1

Browse files
committed
Replace clone with take for argument passing in tail calls
TAIL_CALL: Dynamic tail calls TAIL_CALL_GLOBAL: Named function tail calls
1 parent 4b4bf51 commit 2ffe8f1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/vm.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,10 @@ impl VM {
344344
let arg_start = base + func_reg as usize + 1;
345345
for i in 0..nargs as usize {
346346
unsafe {
347+
// Use take() instead of clone() - the source registers
348+
// won't be accessed again after this tail call
347349
*self.registers.get_unchecked_mut(base + i) =
348-
self.registers.get_unchecked(arg_start + i).clone();
350+
self.registers.get_unchecked_mut(arg_start + i).take();
349351
}
350352
}
351353
ip = 0;
@@ -534,8 +536,10 @@ impl VM {
534536
let src_start = base + first_arg as usize;
535537
for i in 0..nargs as usize {
536538
unsafe {
539+
// Use take() instead of clone() - the source registers
540+
// won't be accessed again after this tail call
537541
*self.registers.get_unchecked_mut(base + i) =
538-
self.registers.get_unchecked(src_start + i).clone();
542+
self.registers.get_unchecked_mut(src_start + i).take();
539543
}
540544
}
541545
ip = 0;
@@ -591,8 +595,10 @@ impl VM {
591595
let src_start = base + first_arg as usize;
592596
for i in 0..nargs as usize {
593597
unsafe {
598+
// Use take() instead of clone() - the source registers
599+
// won't be accessed again after this tail call
594600
*self.registers.get_unchecked_mut(base + i) =
595-
self.registers.get_unchecked(src_start + i).clone();
601+
self.registers.get_unchecked_mut(src_start + i).take();
596602
}
597603
}
598604
ip = 0;

0 commit comments

Comments
 (0)