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

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

Issue 851473002: Use prototype inheritance to reduce number of is check properties. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: dynamically generate is checks for classes Created 5 years, 11 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/old_emitter/emitter.dart
diff --git a/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart b/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart
index 11e028821e99b8d3e3f69d9214512a9c57bcc6b3..03358e1b2657ac5bd0ad55955a99332024f18057 100644
--- a/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart
+++ b/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart
@@ -334,7 +334,7 @@ class OldEmitter implements Emitter {
bool hasIsolateSupport = compiler.hasIsolateSupport;
String fieldNamesProperty = FIELD_NAMES_PROPERTY_NAME;
- jsAst.Expression defineClass = js('''
+ jsAst.Expression defineClass = js(r'''
function(name, fields) {
var accessors = [];
@@ -349,23 +349,24 @@ class OldEmitter implements Emitter {
if (#hasIsolateSupport) { fieldNames += "'" + field + "',"; }
var parameter = "parameter_" + field;
str += parameter;
- body += ("this." + field + " = " + parameter + ";\\n");
+ body += ("this." + field + " = " + parameter + ";\n");
}
- str += ") {\\n" + body + "}\\n";
- str += name + ".builtin\$cls=\\"" + name + "\\";\\n";
- str += "\$desc=\$collectedClasses." + name + ";\\n";
- str += "if(\$desc instanceof Array) \$desc = \$desc[1];\\n";
- str += name + ".prototype = \$desc;\\n";
+ str += ") {\n" + body + "}\n";
+ str += name + ".builtin$cls=\"" + name + "\";\n";
+ str += "$desc=$collectedClasses." + name + ";\n";
+ str += "if($desc instanceof Array) $desc = \$desc[1];\n";
+ str += name + ".prototype = $desc;\n";
if (typeof defineClass.name != "string") {
- str += name + ".name=\\"" + name + "\\";\\n";
+ str += name + ".name=\"" + name + "\";\n";
}
if (#hasIsolateSupport) {
- str += name + ".$fieldNamesProperty=[" + fieldNames + "];\\n";
+ str += name + "." + #fieldNamesProperty + "=[" + fieldNames + "];\n";
floitsch 2015/01/26 16:19:29 long line.
herhut 2015/01/27 11:37:19 Oops. Done.
}
str += accessors.join("");
return str;
- }''', { 'hasIsolateSupport': hasIsolateSupport });
+ }''', { 'hasIsolateSupport': hasIsolateSupport,
+ 'fieldNamesProperty': js.string(fieldNamesProperty)});
// Declare a function called "generateAccessor". This is used in
// defineClassFunction.
@@ -441,6 +442,7 @@ class OldEmitter implements Emitter {
// Fix up the the Dart Object class' prototype.
var prototype = constructor.prototype;
prototype.constructor = constructor;
+ prototype.$isObject = 1;
floitsch 2015/01/26 16:19:29 I think we discussed it, but I changed my mind: th
floitsch 2015/01/26 16:19:29 Are you sure this works? In minified code the name
herhut 2015/01/27 11:37:19 I use the constructor now, which should be a funct
herhut 2015/01/27 11:37:19 Of course it does not :) This was a bit rushed yes
return prototype;
}
tmp.prototype = superConstructor.prototype;
@@ -451,6 +453,7 @@ class OldEmitter implements Emitter {
object[member] = properties[member];
}
}
+ object["$is" + constructor.name] = 1;
floitsch 2015/01/26 16:19:29 Don't just use a magic prefix. I believe that the
herhut 2015/01/27 11:37:19 Done.
object.constructor = constructor;
constructor.prototype = object;
return object;

Powered by Google App Engine
This is Rietveld 408576698