From 8c72ffb4661b74ce0466d0fb68fe10af7bc54582 Mon Sep 17 00:00:00 2001 From: michajlo Date: Mon, 26 Feb 2018 13:09:06 -0800 Subject: Optimize LValue#boundIdentifiers for common case I'm assuming most of the time folks are only assigning one variable, which doesn't require an ImmutableSet.Builder and the garbage it comes with. Also took the liberty of removing some unused InterruptedException declarations. PiperOrigin-RevId: 187068400 --- .../java/com/google/devtools/build/lib/syntax/LValue.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib') diff --git a/src/main/java/com/google/devtools/build/lib/syntax/LValue.java b/src/main/java/com/google/devtools/build/lib/syntax/LValue.java index 2b539a93fe..4cc38f4968 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/LValue.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/LValue.java @@ -92,7 +92,7 @@ public final class LValue extends ASTNode { */ private static void assignIdentifier( Identifier ident, Object value, Environment env, Location loc) - throws EvalException, InterruptedException { + throws EvalException { Preconditions.checkNotNull(value, "trying to assign null to %s", ident); if (env.isKnownGlobalVariable(ident.getName())) { @@ -116,7 +116,7 @@ public final class LValue extends ASTNode { @SuppressWarnings("unchecked") private static void assignItem( Object object, Object key, Object value, Environment env, Location loc) - throws EvalException, InterruptedException { + throws EvalException { if (object instanceof SkylarkDict) { SkylarkDict dict = (SkylarkDict) object; dict.put(key, value, loc, env); @@ -207,9 +207,14 @@ public final class LValue extends ASTNode { * */ public ImmutableSet boundIdentifiers() { - ImmutableSet.Builder result = ImmutableSet.builder(); - collectBoundIdentifiers(expr, result); - return result.build(); + if (expr instanceof Identifier) { + // Common case/fast path - skip the builder. + return ImmutableSet.of((Identifier) expr); + } else { + ImmutableSet.Builder result = ImmutableSet.builder(); + collectBoundIdentifiers(expr, result); + return result.build(); + } } private static void collectBoundIdentifiers( -- cgit v1.2.3