0

I am refactoring a big legacy source file "big.cpp", which contains several class definitions, used solely in this file. e.g., in big.cpp

class A {
  inline void func1() {
    // bla bla ...
  }
  void func2() {
    // bla bla ...
  }
}

some functions are explicitly with in-line keyword, some are not.

As these classes are only in cpp file, not even in header file, it is quite a mess and not possible to unit test, etc. so I am trying to split it into smaller files, as "a.h", "a.cpp"; Then I have a concern. after refactoring, shall these functions be treated as inline functions or not? e.g., I guess func1() shall be inlined, but what about func2()?

I am afraid, if some former inline functions are changed to non-inline, their performance will be slower, so I have to be careful.

pepero
  • 7,095
  • 7
  • 41
  • 72
  • Whether the non inline functions have an impact on performance is not obvious, difference may be negligible. I would carry on with refactoring. – marom Dec 08 '15 at 13:53
  • yeah, as this code is quite sensitive, I have to play safe. – pepero Dec 08 '15 at 14:00

1 Answers1

1

If you define a member function inside a class like func2 in your example, the inline is implied.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • then in this case, all the functions are actually "inline". so there is no way to refactor it without changing the performance. – pepero Dec 08 '15 at 14:04
  • @pepero The `inline` keyword (explicit or implicit) is just a *hint* for the compiler, it's up to the compiler to actually inline the calls. And it might even inline functions that are *not* marked `inline`. And if you measure I doubt you'll find much of a noticeable difference between an inline and a non-inline function these days. – Some programmer dude Dec 08 '15 at 18:09
  • thanks, then I am relieved for this concern. – pepero Dec 08 '15 at 18:11