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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart

Issue 2840613004: Revert "dart2js: --fast-startup: use alias for 'this'" (Closed)
Patch Set: Created 3 years, 8 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 | « no previous file | no next file » | 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 part of dart2js.js_emitter.startup_emitter.model_emitter; 5 part of dart2js.js_emitter.startup_emitter.model_emitter;
6 6
7 /// The name of the property that stores the tear-off getter on a static 7 /// The name of the property that stores the tear-off getter on a static
8 /// function. 8 /// function.
9 /// 9 ///
10 /// This property is only used when isolates are used. 10 /// This property is only used when isolates are used.
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 /// 646 ///
647 /// The constructor is statically built. 647 /// The constructor is statically built.
648 js.Expression emitConstructor(Class cls) { 648 js.Expression emitConstructor(Class cls) {
649 js.Name name = cls.name; 649 js.Name name = cls.name;
650 // If the class is not directly instantiated we only need it for inheritance 650 // If the class is not directly instantiated we only need it for inheritance
651 // or RTI. In either case we don't need its fields. 651 // or RTI. In either case we don't need its fields.
652 if (cls.isNative || !cls.isDirectlyInstantiated) { 652 if (cls.isNative || !cls.isDirectlyInstantiated) {
653 return js.js('function #() { }', name); 653 return js.js('function #() { }', name);
654 } 654 }
655 655
656 var statements = <js.Statement>[]; 656 List<js.Name> fieldNames =
657 var parameters = <js.Name>[]; 657 cls.fields.map((Field field) => field.name).toList();
658 var thisRef; 658 if (cls.hasRtiField) {
659 659 fieldNames.add(namer.rtiFieldJsName);
660 // If there are many references to `this`, cache it in a local.
661 if (cls.fields.length + (cls.hasRtiField ? 1 : 0) >= 4) {
662 statements.add(js.js.statement('var _ = this;'));
663 thisRef = js.js('_');
664 } else {
665 thisRef = js.js('this');
666 } 660 }
667 661
668 for (Field field in cls.fields) { 662 Iterable<js.Name> assignments = fieldNames.map((js.Name field) {
669 js.Name paramName = field.name; 663 return js.js("this.#field = #field", {"field": field});
670 parameters.add(paramName); 664 });
671 statements
672 .add(js.js.statement('#.# = #', [thisRef, field.name, paramName]));
673 }
674 665
675 if (cls.hasRtiField) { 666 // TODO(sra): Cache 'this' in a one-character local for 4 or more uses of
676 js.Name paramName = namer.rtiFieldJsName; 667 // 'this'. i.e. "var _=this;_.a=a;_.b=b;..."
677 parameters.add(paramName);
678 statements.add(js.js
679 .statement('#.# = #', [thisRef, namer.rtiFieldJsName, paramName]));
680 }
681 668
682 return js.js('function #(#) { # }', [name, parameters, statements]); 669 // TODO(sra): Separate field and field initializer parameter names so the
670 // latter may be fully minified.
671
672 return js.js('function #(#) { # }', [name, fieldNames, assignments]);
683 } 673 }
684 674
685 /// Emits the prototype-section of the fragment. 675 /// Emits the prototype-section of the fragment.
686 /// 676 ///
687 /// This section updates the prototype-property of all constructors in the 677 /// This section updates the prototype-property of all constructors in the
688 /// global holders. 678 /// global holders.
689 js.Statement emitPrototypes(Fragment fragment) { 679 js.Statement emitPrototypes(Fragment fragment) {
690 List<js.Statement> assignments = fragment.libraries 680 List<js.Statement> assignments = fragment.libraries
691 .expand((Library library) => library.classes) 681 .expand((Library library) => library.classes)
692 .map((Class cls) { 682 .map((Class cls) {
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after
1444 } 1434 }
1445 statements.add(js.js.statement("setOrUpdateInterceptorsByTag(#);", 1435 statements.add(js.js.statement("setOrUpdateInterceptorsByTag(#);",
1446 js.objectLiteral(interceptorsByTag))); 1436 js.objectLiteral(interceptorsByTag)));
1447 statements.add( 1437 statements.add(
1448 js.js.statement("setOrUpdateLeafTags(#);", js.objectLiteral(leafTags))); 1438 js.js.statement("setOrUpdateLeafTags(#);", js.objectLiteral(leafTags)));
1449 statements.addAll(subclassAssignments); 1439 statements.addAll(subclassAssignments);
1450 1440
1451 return wrapPhase('nativeSupport', new js.Block(statements)); 1441 return wrapPhase('nativeSupport', new js.Block(statements));
1452 } 1442 }
1453 } 1443 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698