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

Unified Diff: pkg/compiler/lib/src/js_emitter/new_emitter/emitter.dart

Issue 947333004: dart2js: simplify constant expression generation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 months 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: pkg/compiler/lib/src/js_emitter/new_emitter/emitter.dart
diff --git a/pkg/compiler/lib/src/js_emitter/new_emitter/emitter.dart b/pkg/compiler/lib/src/js_emitter/new_emitter/emitter.dart
index c37d5338e9d02c14656d6622e376ac0b5b295826..7282656ca71b0e1d4183342ed4d8622ab2348f19 100644
--- a/pkg/compiler/lib/src/js_emitter/new_emitter/emitter.dart
+++ b/pkg/compiler/lib/src/js_emitter/new_emitter/emitter.dart
@@ -40,38 +40,18 @@ class Emitter implements emitterTask.Emitter {
// TODO(floitsch): copied from OldEmitter. Adjust or share.
@override
bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant) {
- if (constant.isFunction) return true; // Already emitted.
- if (constant.isPrimitive) return true; // Inlined.
- if (constant.isDummy) return true; // Inlined.
- // The name is null when the constant is already a JS constant.
- // TODO(floitsch): every constant should be registered, so that we can
- // share the ones that take up too much space (like some strings).
- if (namer.constantName(constant) == null) return true;
- return false;
+ return _emitter.isConstantInlinedOrAlreadyEmitted(constant);
}
// TODO(floitsch): copied from OldEmitter. Adjust or share.
@override
int compareConstants(ConstantValue a, ConstantValue b) {
- // Inlined constants don't affect the order and sometimes don't even have
- // names.
- int cmp1 = isConstantInlinedOrAlreadyEmitted(a) ? 0 : 1;
- int cmp2 = isConstantInlinedOrAlreadyEmitted(b) ? 0 : 1;
- if (cmp1 + cmp2 < 2) return cmp1 - cmp2;
-
- // Emit constant interceptors first. Constant interceptors for primitives
- // might be used by code that builds other constants. See Issue 18173.
- if (a.isInterceptor != b.isInterceptor) {
- return a.isInterceptor ? -1 : 1;
- }
-
- // Sorting by the long name clusters constants with the same constructor
- // which compresses a tiny bit better.
- int r = namer.constantLongName(a).compareTo(namer.constantLongName(b));
- if (r != 0) return r;
- // Resolve collisions in the long name by using the constant name (i.e. JS
- // name) which is unique.
- return namer.constantName(a).compareTo(namer.constantName(b));
+ return _emitter.compareConstants(a, b);
+ }
+
+ @override
+ js.Expression constantReference(ConstantValue value) {
+ return _emitter.generateConstantReference(value);
}
@override
@@ -85,11 +65,6 @@ class Emitter implements emitterTask.Emitter {
return js.js('function() {}');
}
- @override
- js.Expression constantReference(ConstantValue value) {
- return _emitter.constantEmitter.reference(value);
- }
-
js.PropertyAccess _globalPropertyAccess(Element element) {
String name = namer.getNameX(element);
js.PropertyAccess pa = new js.PropertyAccess.field(
@@ -106,8 +81,7 @@ class Emitter implements emitterTask.Emitter {
@override
js.Expression isolateStaticClosureAccess(FunctionElement element) {
- return js.js('#.#()',
- [namer.globalObjectFor(element), namer.getStaticClosureName(element)]);
+ return _emitter.generateStaticClosureAccess(element);
}
@override

Powered by Google App Engine
This is Rietveld 408576698