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

Unified Diff: pkg/compiler/lib/src/js_emitter/type_test_generator.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/type_test_generator.dart
diff --git a/pkg/compiler/lib/src/js_emitter/type_test_generator.dart b/pkg/compiler/lib/src/js_emitter/type_test_generator.dart
index 2c9ce0d9ee1c64dc6a725bbea143105464044714..a2db59dc22e2321da233987df97e6c8fe4639124 100644
--- a/pkg/compiler/lib/src/js_emitter/type_test_generator.dart
+++ b/pkg/compiler/lib/src/js_emitter/type_test_generator.dart
@@ -57,12 +57,16 @@ class TypeTestGenerator {
TypeTestProperties result = new TypeTestProperties();
+ /// Generates an is-test if the test is not inherited from a superclass
+ /// anyway. This assumes that for every class an is-tests is generated
floitsch 2015/01/26 16:19:29 -anyway-.
herhut 2015/01/27 11:37:20 Done.
+ /// dyanically at runtime anyway. We also always generate tests against
floitsch 2015/01/26 16:19:29 dynamically.
herhut 2015/01/27 11:37:19 Done.
+ /// native classes.
+ /// TODO(herhut): Generate tests for native classes dynamically, as well.
void generateIsTest(Element other) {
- if (other == compiler.objectClass && other != classElement) {
- // Avoid emitting `$isObject` on all classes but [Object].
- return;
+ if (classElement.isNative ||
+ !compiler.world.isSubclassOf(classElement, other)) {
+ result.properties[namer.operatorIs(other)] = js('1');
floitsch 2015/01/26 16:19:29 probably ok to have the 1 here instead of a functi
herhut 2015/01/27 11:37:20 Acknowledged.
}
- result.properties[namer.operatorIs(other)] = js('true');
}
void generateFunctionTypeSignature(FunctionElement method,
@@ -108,8 +112,7 @@ class TypeTestGenerator {
void generateTypeCheck(TypeCheck check) {
ClassElement checkedClass = check.cls;
- // We must not call [generateIsTest] since we also want is$Object.
- result.properties[namer.operatorIs(checkedClass)] = js('true');
+ generateIsTest(checkedClass);
Substitution substitution = check.substitution;
if (substitution != null) {
jsAst.Expression body = substitution.getCode(backend.rti);

Powered by Google App Engine
This is Rietveld 408576698