aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib
diff options
context:
space:
mode:
authorGravatar michajlo <michajlo@google.com>2018-02-26 13:09:06 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-26 13:10:43 -0800
commit8c72ffb4661b74ce0466d0fb68fe10af7bc54582 (patch)
tree6e5d37da7f01467ebb925bfb47fe75fb0fc8ab9f /src/main/java/com/google/devtools/build/lib
parent0b59342ad5e4935368c790799dfc9c7b192b6225 (diff)
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
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/LValue.java15
1 files changed, 10 insertions, 5 deletions
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<Object, Object> dict = (SkylarkDict<Object, Object>) object;
dict.put(key, value, loc, env);
@@ -207,9 +207,14 @@ public final class LValue extends ASTNode {
* </ul>
*/
public ImmutableSet<Identifier> boundIdentifiers() {
- ImmutableSet.Builder<Identifier> 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<Identifier> result = ImmutableSet.builder();
+ collectBoundIdentifiers(expr, result);
+ return result.build();
+ }
}
private static void collectBoundIdentifiers(