Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Unified Diff: compiler/java/com/google/dart/compiler/backend/js/ast/JsScope.java

Issue 8659022: Puts JsScope on a diet (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Changed the strategy to only walk a specific class when TranslationContext is created Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
}
}
« no previous file with comments | « compiler/java/com/google/dart/compiler/backend/js/TranslationContext.java ('k') | compiler/scripts/dartc.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698