Twoje komentarze
- This is a very trivial calculation.
- 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.
Customer support service by UserEcho
And it's discussed in the Good To Know / Performance section in https://refactoring.guru/replace-temp-with-query.