| Index: compiler/java/com/google/dart/compiler/backend/js/ast/JsScope.java
|
| diff --git a/compiler/java/com/google/dart/compiler/backend/js/ast/JsScope.java b/compiler/java/com/google/dart/compiler/backend/js/ast/JsScope.java
|
| index 178f85e51f642519a25c80a142df8dd0b4c4abbf..d61cea78442573cb99bc61b64b07eaa21918cb7d 100644
|
| --- a/compiler/java/com/google/dart/compiler/backend/js/ast/JsScope.java
|
| +++ b/compiler/java/com/google/dart/compiler/backend/js/ast/JsScope.java
|
| @@ -4,6 +4,8 @@
|
|
|
| package com.google.dart.compiler.backend.js.ast;
|
|
|
| +import com.google.common.collect.Interner;
|
| +import com.google.common.collect.Interners;
|
| import com.google.dart.compiler.util.Lists;
|
| import com.google.dart.compiler.util.Maps;
|
|
|
| @@ -43,25 +45,26 @@ public class JsScope implements Serializable {
|
|
|
| private List<JsScope> children = Collections.emptyList();
|
| private final String description;
|
| - private Map<String, JsName> names = Collections.emptyMap();
|
| + private Map<String, JsName> names; // Lazy init to save memory
|
| private JsScope parent;
|
| protected int tempIndex = 0;
|
| private final String scopeId;
|
| + private static Interner<String> interner = Interners.newWeakInterner();
|
|
|
| - /*
|
| + /*
|
| * Create a scope with parent.
|
| */
|
| public JsScope(JsScope parent, String description) {
|
| this(parent, description, null);
|
| }
|
| -
|
| +
|
| /**
|
| * Create a scope with parent.
|
| */
|
| public JsScope(JsScope parent, String description, String scopeId) {
|
| assert (parent != null);
|
| this.scopeId = scopeId;
|
| - this.description = description;
|
| + this.description = interner.intern(description);
|
| this.parent = parent;
|
| parent.children = Lists.add(parent.children, this);
|
| }
|
| @@ -241,8 +244,12 @@ public class JsScope implements Serializable {
|
| /**
|
| * Returns an iterator for all the names defined by this scope.
|
| */
|
| + @SuppressWarnings("unchecked")
|
| public Iterator<JsName> getAllNames() {
|
| - return names.values().iterator();
|
| + if (names != null) {
|
| + return names.values().iterator();
|
| + }
|
| + return Collections.EMPTY_LIST.iterator();
|
| }
|
|
|
| /**
|
| @@ -282,6 +289,9 @@ public class JsScope implements Serializable {
|
| */
|
| protected JsName doCreateName(String ident, String shortIdent, String originalName) {
|
| JsName name = new JsName(this, ident, shortIdent, originalName);
|
| + if (names == null) {
|
| + names = Maps.create();
|
| + }
|
| names = Maps.putOrdered(names, ident, name);
|
| return name;
|
| }
|
| @@ -293,6 +303,9 @@ public class JsScope implements Serializable {
|
| * @return <code>null</code> if the identifier has no associated name
|
| */
|
| protected JsName findExistingNameNoRecurse(String ident) {
|
| - return names.get(ident);
|
| + if (names != null) {
|
| + return names.get(ident);
|
| + }
|
| + return null;
|
| }
|
| }
|
|
|