Optimize boolean and/or operators by short-circuit and evaluating the branch with lowest cost first.