Given the following case:
state = true;
// ..
We could use an alternative pattern like:
if (!state)
{
state = true;
}
// ..
In either case, field state
must be assigned to true
. Is there a proper argument to evaluate a boolean before setting it? It would effectively replace one virtual instruction by two.
Assuming that reading is cheaper than writing, I think the latter example could prove as an optimization.
Note that these code fragments recur (heavily), so the value of state
cannot be predetermined as false
.
Aucun commentaire:
Enregistrer un commentaire