I saw a lot of posts about declaring methods as inline
.
One of the rule of thumb to use inline
is when the method is very small.
I guess there is no specific number for it - but how small is very small?
1 line (for example - Getter
/Setter
)?
~10/100 lines?
I have a 20 line template function which uses many constants (for the logic to be clear).
I could write it as a 1 liner, but it would not be understandable as easily.
When compiled with optimization the function can sometimes be just 1 assembler instruction. So it is marked for inline.
So lines of code is not a good measure.
inline
is just a hint for the compiler. It doesn't have to inline. And even when there is no inline
the compiler can do it.
I do research before applying inline, as there can be negative consequences (code slowing down due to bloat).
So as usual, measure if it improves your code.