Micro-optimize if-block evaluation
Most of the time there's only one, doesn't justify the iterator overhead.
PiperOrigin-RevId: 187031802
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Eval.java b/src/main/java/com/google/devtools/build/lib/syntax/Eval.java
index a13a9fc..33ce442 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Eval.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Eval.java
@@ -111,7 +111,10 @@
}
void execIf(IfStatement node) throws EvalException, InterruptedException {
- for (IfStatement.ConditionalStatements stmt : node.getThenBlocks()) {
+ ImmutableList<IfStatement.ConditionalStatements> thenBlocks = node.getThenBlocks();
+ // Avoid iterator overhead - most of the time there will be one or few "if"s.
+ for (int i = 0; i < thenBlocks.size(); i++) {
+ IfStatement.ConditionalStatements stmt = thenBlocks.get(i);
if (EvalUtils.toBoolean(stmt.getCondition().eval(env))) {
exec(stmt);
return;