Reputation: 6196
private bool _invalidated
public void Invalidate()
{
_invalidated = true;
}
or
public void Invalidate()
{
if(!_invalidated)
{
_invalidated = true;
}
}
Which would be faster?
This will be called many many times.
Upvotes: 0
Views: 96
Reputation: 561
As Andreas says, it depends. And as I4V says, paraphrased, it doesn't matter.
I would go for the first, less code and prettier(of course subjective).
Upvotes: 0
Reputation: 560
The first is less instructions, and contains no conditional, so it's preferable. However, the second would probably be optimized away by a sufficiently smart compiler / JITer.
Upvotes: 1