Open
Description
The following talks about Debug::fmt
, but is likely true of a lot more methods applied to arrays.
Take the following code:
fn main() {
let a = [1, 2, 3];
let b = [1, 2, 3, 4];
let c = [1, 2, 3, 4, 5];
let d = [1, 2, 3, 4, 5, 6];
println!("{:?}", a);
println!("{:?}", b);
println!("{:?}", c);
println!("{:?}", d);
}
Compiled with --release, you end up with 4 different functions for core::array::<impl core::fmt::Debug for [T; N]>::fmt
(BTW, shouldn't they each have their N replaced by the actual number?). To add insult to injury, each of these have their loops unrolled, so the longer the array, the larger the function, up to 59 (!).
Almost ironically, building with -C opt-level=1
generates 4 functions that create a slice and a separate, common, fmt
function for it.
This is one of these cases where you'd probably want a #[inline(never)]
at the call site in core::array::<impl core::fmt::Debug for [T; N]>::fmt
if that were possible.