3 ms·
Here's a case I stumble on: Rust seems to generate unnecessary branches. Compare copying an optional range: C++: https://godbolt.org/z/VCf638 https://godbolt.o
by ridiculous_fish 6y ago
Here's a case I stumble on: Rust seems to generate unnecessary branches. Compare copying an optional range:
C++: https://godbolt.org/z/VCf638 https://godbolt.org/z/VCf638
Rust: https://rust.godbolt.org/z/jRFiw_ https://rust.godbolt.org/z/jRFiw_
I think the key difference here is that C++ allows specializing optional on trivial types - can anyone shed more light?
- sigwinch28 6y agoIt looks like the C++ version always does the copy, regardless of whether or not the optional is empty, whereas Rust only bothers copying if there's anything there. Is this a remnant of #[inline] on Option's Clone impl methods? With "larger" types (e.g. an optional several-GiB array) it seems like this could save some time depending on where things are in memory.