void x(){
thisIsALongFunction();
}
如上图所示的代码, x()
中只有一句话, 但是它所调用的函数很长, 这种情况下需要inline
吗?
高洛峰2017-04-17 14:29:40
inline
This is just a suggestion to the compiler, not a requirement.
However, the implementation of mainstream compilers will ignore your suggestions. If you turn on O2
, short functions will be automatically inlined, but long functions will not be inlined. So ignore it.
阿神2017-04-17 14:29:40
Add it, inlining will remove your extra layer of encapsulation, and the encapsulation inside should still be there
黄舟2017-04-17 14:29:40
Don’t worry about these issues, it doesn’t matter whether the code optimized by the compiler is inline
or not.