Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library deferred_load; | 5 library deferred_load; |
| 6 | 6 |
| 7 import 'dart2jslib.dart' show | 7 import 'dart2jslib.dart' show |
| 8 Compiler, | 8 Compiler, |
| 9 CompilerTask, | 9 CompilerTask, |
| 10 Constant, | 10 Constant, |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 611 | 611 |
| 612 _assignNamesToOutputUnits(allOutputUnits); | 612 _assignNamesToOutputUnits(allOutputUnits); |
| 613 }); | 613 }); |
| 614 } | 614 } |
| 615 | 615 |
| 616 void ensureMetadataResolved(Compiler compiler) { | 616 void ensureMetadataResolved(Compiler compiler) { |
| 617 _allDeferredImports[_fakeMainImport] = compiler.mainApp; | 617 _allDeferredImports[_fakeMainImport] = compiler.mainApp; |
| 618 bool deferredUsedFromMain = false; | 618 bool deferredUsedFromMain = false; |
| 619 var lastDeferred; | 619 var lastDeferred; |
| 620 for (LibraryElement library in compiler.libraries.values) { | 620 for (LibraryElement library in compiler.libraries.values) { |
| 621 Map<String, List<Import>> prefixImports = {}; | |
|
floitsch
2014/02/17 14:39:26
Move outside the loop, and just clear it at every
sigurdm
2014/02/18 08:49:53
Done.
| |
| 621 // TODO(sigurdm): Make helper getLibraryImportTags when tags is a List | 622 // TODO(sigurdm): Make helper getLibraryImportTags when tags is a List |
| 622 // instead of a Link. | 623 // instead of a Link. |
| 623 for (LibraryTag tag in library.tags) { | 624 for (LibraryTag tag in library.tags) { |
| 624 if (tag is! Import) continue; | 625 if (tag is! Import) continue; |
| 625 Import import = tag; | 626 Import import = tag; |
| 626 if (_isImportDeferred(import)) { | 627 if (_isImportDeferred(import)) { |
| 628 if (import.prefix == null) { | |
| 629 compiler.reportError( | |
| 630 import, | |
| 631 MessageKind.DEFERRED_LIBRARY_WITHOUT_PREFIX); | |
| 632 } | |
| 627 splitProgram = true; | 633 splitProgram = true; |
| 628 _allDeferredImports[tag] = library.getLibraryFromTag(tag); | 634 _allDeferredImports[tag] = library.getLibraryFromTag(tag); |
| 629 lastDeferred = import.metadata.first; | 635 lastDeferred = import.metadata.first; |
| 630 if (library == compiler.mainApp) { | 636 if (library == compiler.mainApp) { |
| 631 deferredUsedFromMain = true; | 637 deferredUsedFromMain = true; |
| 632 } | 638 } |
| 633 } | 639 } |
| 640 if (import.prefix != null) { | |
| 641 prefixImports.putIfAbsent(import.prefix.toString(), | |
| 642 () => new List<Import>()).add(import); | |
|
floitsch
2014/02/17 14:39:26
Instead of allocating a new closure/list every tim
sigurdm
2014/02/18 08:49:53
I wanted to do something like that first - but it
| |
| 643 } | |
| 644 } | |
| 645 for (String prefix in prefixImports.keys) { | |
| 646 List<Import> imports = prefixImports[prefix]; | |
| 647 if (imports.length <= 1) continue; | |
| 648 for (Import import in imports) { | |
| 649 if (_isImportDeferred(import)) { | |
| 650 compiler.reportError(import, | |
| 651 MessageKind.DEFERRED_LIBRARY_DUPLICATE_PREFIX); | |
| 652 } | |
| 653 } | |
| 634 } | 654 } |
| 635 } | 655 } |
| 636 if (splitProgram && !deferredUsedFromMain) { | 656 if (splitProgram && !deferredUsedFromMain) { |
| 637 compiler.reportInfo( | 657 compiler.reportInfo( |
| 638 lastDeferred, | 658 lastDeferred, |
| 639 MessageKind.DEFERRED_LIBRARY_NOT_FROM_MAIN); | 659 MessageKind.DEFERRED_LIBRARY_NOT_FROM_MAIN); |
| 640 splitProgram = false; | 660 splitProgram = false; |
| 641 } | 661 } |
| 642 } | 662 } |
| 643 } | 663 } |
| OLD | NEW |