Closed
Description
This function uses ~1Kb of stack (with optimisations)
function test() -> [u8,...256] {
let x : [u8, ..256];
let val = get_val();
if val == 0 {
x = [1, ..256];
return x;
} else if val == 1 {
x = [4, ..256];
return x;
} else {
x = [9, ..256];
return x;
}
}
While this function uses ~256 bytes of stack:
function test() -> [u8,...256] {
let x : [u8, ..256];
let val = get_val();
if val == 0 {
x = [1, ..256];
} else if val == 1 {
x = [4, ..256];
} else {
x = [9, ..256];
}
return x;
}
As far as I can tell, each return statement gets given it's own slot which is copied into the return pointer at the end. This happens to also result in 4 memcpy
calls in total.
Metadata
Metadata
Assignees
Labels
No labels