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

Side by Side Diff: lib/src/compiler/code_generator.dart

Issue 1999273002: fix performance of setType (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | tool/input_sdk/private/ddc_runtime/classes.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:collection' show HashMap, HashSet; 5 import 'dart:collection' show HashMap, HashSet;
6 import 'dart:math' show min, max; 6 import 'dart:math' show min, max;
7 7
8 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 8 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType; 10 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType;
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 690
691 var body = <JS.Statement>[]; 691 var body = <JS.Statement>[];
692 var extensions = _extensionsToImplement(classElem); 692 var extensions = _extensionsToImplement(classElem);
693 _initExtensionSymbols(classElem, methods, fields, body); 693 _initExtensionSymbols(classElem, methods, fields, body);
694 _emitSuperHelperSymbols(_superHelperSymbols, body); 694 _emitSuperHelperSymbols(_superHelperSymbols, body);
695 695
696 // Emit the class, e.g. `core.Object = class Object { ... }` 696 // Emit the class, e.g. `core.Object = class Object { ... }`
697 _defineClass(classElem, className, classExpr, body); 697 _defineClass(classElem, className, classExpr, body);
698 698
699 // Emit things that come after the ES6 `class ... { ... }`. 699 // Emit things that come after the ES6 `class ... { ... }`.
700 _setBaseClass(classElem, className, body); 700 var jsPeerName = _getJSPeerName(classElem);
701 _setBaseClass(classElem, className, jsPeerName, body);
701 _defineNamedConstructors(ctors, body, className); 702 _defineNamedConstructors(ctors, body, className);
702 _emitVirtualFieldSymbols(virtualFieldSymbols, body); 703 _emitVirtualFieldSymbols(virtualFieldSymbols, body);
703 _emitClassSignature(methods, classElem, ctors, extensions, className, body); 704 _emitClassSignature(methods, classElem, ctors, extensions, className, body);
704 _defineExtensionMembers(extensions, className, body); 705 _defineExtensionMembers(extensions, className, body);
705 _emitClassMetadata(node.metadata, className, body); 706 _emitClassMetadata(node.metadata, className, body);
706 707
707 JS.Statement classDef = _statement(body); 708 JS.Statement classDef = _statement(body);
708 var typeFormals = classElem.typeParameters; 709 var typeFormals = classElem.typeParameters;
709 if (typeFormals.isNotEmpty) { 710 if (typeFormals.isNotEmpty) {
710 classDef = _defineClassTypeArguments(classElem, typeFormals, classDef); 711 classDef = _defineClassTypeArguments(classElem, typeFormals, classDef);
711 } 712 }
712 713
713 body = <JS.Statement>[classDef]; 714 body = <JS.Statement>[classDef];
714 _emitStaticFields(staticFields, staticFieldOverrides, classElem, body); 715 _emitStaticFields(staticFields, staticFieldOverrides, classElem, body);
715 _registerExtensionType(classElem, body); 716 _registerExtensionType(classElem, jsPeerName, body);
716 return _statement(body); 717 return _statement(body);
717 } 718 }
718 719
719 void _emitSuperHelperSymbols( 720 void _emitSuperHelperSymbols(
720 List<JS.TemporaryId> superHelperSymbols, List<JS.Statement> body) { 721 List<JS.TemporaryId> superHelperSymbols, List<JS.Statement> body) {
721 for (var id in superHelperSymbols) { 722 for (var id in superHelperSymbols) {
722 body.add(js.statement('const # = Symbol(#)', [id, js.string(id.name)])); 723 body.add(js.statement('const # = Symbol(#)', [id, js.string(id.name)]));
723 } 724 }
724 superHelperSymbols.clear(); 725 superHelperSymbols.clear();
725 } 726 }
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 classElem, 1135 classElem,
1135 (a) => 1136 (a) =>
1136 isJsPeerInterface(a) || 1137 isJsPeerInterface(a) ||
1137 isNativeAnnotation(a) && _extensionTypes.isNativeClass(classElem)); 1138 isNativeAnnotation(a) && _extensionTypes.isNativeClass(classElem));
1138 if (jsPeerName != null && jsPeerName.contains(',')) { 1139 if (jsPeerName != null && jsPeerName.contains(',')) {
1139 jsPeerName = jsPeerName.split(',')[0]; 1140 jsPeerName = jsPeerName.split(',')[0];
1140 } 1141 }
1141 return jsPeerName; 1142 return jsPeerName;
1142 } 1143 }
1143 1144
1144 void _registerExtensionType(ClassElement classElem, List<JS.Statement> body) { 1145 void _registerExtensionType(
1145 var jsPeerName = _getJSPeerName(classElem); 1146 ClassElement classElem, String jsPeerName, List<JS.Statement> body) {
1146 if (jsPeerName != null) { 1147 if (jsPeerName != null) {
1147 // TODO(jmesserly): this copies the dynamic members.
1148 // Probably fine for objects coming from JS, but not if we actually
1149 // want to support construction of instances with generic types other
1150 // than dynamic. See issue #154 for Array and List<E> related bug.
1151 body.add(js.statement('dart.registerExtension(dart.global.#, #);', 1148 body.add(js.statement('dart.registerExtension(dart.global.#, #);',
1152 [_propertyName(jsPeerName), _emitTopLevelName(classElem)])); 1149 [_propertyName(jsPeerName), _emitTopLevelName(classElem)]));
1153 } 1150 }
1154 } 1151 }
1155 1152
1156 void _setBaseClass(ClassElement classElem, JS.Expression className, 1153 void _setBaseClass(ClassElement classElem, JS.Expression className,
1157 List<JS.Statement> body) { 1154 String jsPeerName, List<JS.Statement> body) {
1158 String jsPeerName = _getJSPeerName(classElem);
1159 JS.Expression newBaseClass;
1160 if (jsPeerName != null && classElem.typeParameters.isNotEmpty) { 1155 if (jsPeerName != null && classElem.typeParameters.isNotEmpty) {
1161 // TODO(jmesserly): we should really just extend Array in the first place. 1156 // TODO(jmesserly): we should really just extend Array in the first place.
1162 newBaseClass = js.call('dart.global.#', [jsPeerName]); 1157 var newBaseClass = js.call('dart.global.#', [jsPeerName]);
1158 body.add(js.statement(
1159 'dart.setExtensionBaseClass(#, #);', [className, newBaseClass]));
1163 } else if (_hasDeferredSupertype.contains(classElem)) { 1160 } else if (_hasDeferredSupertype.contains(classElem)) {
1164 newBaseClass = _emitType(classElem.type.superclass, 1161 var newBaseClass = _emitType(classElem.type.superclass,
1165 subClass: classElem, className: className); 1162 subClass: classElem, className: className);
1166 }
1167 if (newBaseClass != null) {
1168 body.add( 1163 body.add(
1169 js.statement('dart.setBaseClass(#, #);', [className, newBaseClass])); 1164 js.statement('dart.setBaseClass(#, #);', [className, newBaseClass]));
1170 } 1165 }
1171 } 1166 }
1172 1167
1173 void _defineNamedConstructors(List<ConstructorDeclaration> ctors, 1168 void _defineNamedConstructors(List<ConstructorDeclaration> ctors,
1174 List<JS.Statement> body, JS.Expression className) { 1169 List<JS.Statement> body, JS.Expression className) {
1175 for (ConstructorDeclaration member in ctors) { 1170 for (ConstructorDeclaration member in ctors) {
1176 if (member.name != null && member.factoryKeyword == null) { 1171 if (member.name != null && member.factoryKeyword == null) {
1177 body.add(js.statement('dart.defineNamedConstructor(#, #);', 1172 body.add(js.statement('dart.defineNamedConstructor(#, #);',
(...skipping 3379 matching lines...) Expand 10 before | Expand all | Expand 10 after
4557 } 4552 }
4558 4553
4559 bool isLibraryPrefix(Expression node) => 4554 bool isLibraryPrefix(Expression node) =>
4560 node is SimpleIdentifier && node.staticElement is PrefixElement; 4555 node is SimpleIdentifier && node.staticElement is PrefixElement;
4561 4556
4562 LibraryElement _getLibrary(AnalysisContext c, String uri) => 4557 LibraryElement _getLibrary(AnalysisContext c, String uri) =>
4563 c.computeLibraryElement(c.sourceFactory.forUri(uri)); 4558 c.computeLibraryElement(c.sourceFactory.forUri(uri));
4564 4559
4565 bool _isDartRuntime(LibraryElement l) => 4560 bool _isDartRuntime(LibraryElement l) =>
4566 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; 4561 l.isInSdk && l.source.uri.toString() == 'dart:_runtime';
OLDNEW
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | tool/input_sdk/private/ddc_runtime/classes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698