3 ms·
LLVM has at least two optimizations that can elide moves in different circumstances, MemCpyOpt and SROA. But it depends on the situation. If you call a functi
by comex 5y ago
LLVM has at least two optimizations that can elide moves in different circumstances, MemCpyOpt and SROA. But it depends on the situation. If you call a function that moves its argument to its return value, that move definitely won't get elided if the function is not inlined. But simple functions are likely to be inlined.
- nextaccountic 5y ago> If you call a function that moves its argument to its return value, that move definitely won't get elided if the function is not inlined. Wow that's worse than I thought. This means that any pub function that does this pattern of taking ownership then giving it back should have at least #[inline] to enable inlining across crates, or maybe even #[inline(always)]. The difference to C to C++ is that in Rust, such pattern is sometimes necessary to work around the borrow checker.