I am recently trying to improve the code quality of a side-project and I was wondering something about cache...
Let's suppose we have the following code:
if(a || b)
Now, let's imagine a
and b
are actually very long operations e.g:
element.getValue(anIndexContainer[anotherSubItemCauseReasons])
What I would do is of course to make it readable as, for instance:
bool shouldDoSomething = a || b
// the bool will NEVER be used after the if
if(shouldDoSomething)
My question is: does this consume more cache?
My guess is that since the bool is declared right before the if
and they are never re-used, the compiling optimizes it as it is in the first case.
Is there any evidence/proof/spec about the behaviour C# compiler would have?
FOR FUTURE READERS:
This link is the example of what the compiler does, credits to @stefano balzarotti for the link :)