8 ms·
The thing with `inline` as an optimisation is that it's not about optimising by inlining directly. It's a promise about how you intend to use the function. It'
by CuriousCosmic 2y ago
The thing with `inline` as an optimisation is that it's not about optimising by inlining directly. It's a promise about how you intend to use the function.
It's not just "you can have multiple definitions of the same function" but rather a promise that the function doesn't need to be address/pointer equivalent between translation units. This is arguably more important than inlining directly because it means the compiler can fully deduce how the function may be used without any LTO or other cross translation unit optimisation techniques.
Of course you could still technically expose a pointer to the function outside a TU but doing so would be obvious to the compiler and it can fall back to generating a strictly conformant version of the function. Otherwise however it can potentially deduce that some branches in said function are unreachable and eliminate them or otherwise specialise the code for the specific use cases in that TU. So it potentially opens up alternative optimisations even if there's still a function call and it's not inlined directly.