你的评论

  1. This is a very trivial calculation.
  2. It is written 3x but executed 2x since it's in the if-else.

The overhead is most likely negligible.

In general, you shouldn't start from the assumption that it has any noticeable overhead and complicate your code or not do the refactoring based on that assumption (which is most often false). Only if profiling reveals that it might pay off. Furthermore, e.g. in the case of C++, the compiler might inline it automatically anyway.



UserEcho 的客户支持