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

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: Comments. 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 f4b184f4405c63c0a27efaa2491a60ae17768125..5ff5e0071ae2ec53e41fa8566c2a295be6037a0e 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
+ /// This assumes that for every class an is-tests is generated
+ /// dynamically at runtime. We also always generate tests against
+ /// 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');
}
- 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