aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/syntax
diff options
context:
space:
mode:
authorGravatar michajlo <michajlo@google.com>2018-02-26 09:19:11 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-26 09:21:14 -0800
commitae9a881f725b03c16c75faae4eccaf00bdc7fdf0 (patch)
treed98b7eee540f051ef766a9ab741a1347dfe8bcf7 /src/main/java/com/google/devtools/build/lib/syntax
parent9dfb1ee2fc1b6e312105ad2062ec963d28b916e6 (diff)
Micro-optimize if-block evaluation
Most of the time there's only one, doesn't justify the iterator overhead. PiperOrigin-RevId: 187031802
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/Eval.java5
1 files changed, 4 insertions, 1 deletions
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 a13a9fc184..33ce4426bb 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 @@ public class Eval {
}
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;