| 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 part of dart2js.js_emitter.program_builder; | 5 part of dart2js.js_emitter.program_builder; |
| 6 | 6 |
| 7 /// A Fragment maps [LibraryElement]s to their [Element]s. | 7 /// A Fragment maps [LibraryElement]s to their [Element]s. |
| 8 /// | 8 /// |
| 9 /// Fundamentally, this class nicely encapsulates a | 9 /// Fundamentally, this class nicely encapsulates a |
| 10 /// `Map<LibraryElement, List<Element>>`. | 10 /// `Map<LibraryElement, List<Element>>`. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // Add one for the main fragment. | 57 // Add one for the main fragment. |
| 58 int get fragmentCount => _deferredFragmentsMap.length + 1; | 58 int get fragmentCount => _deferredFragmentsMap.length + 1; |
| 59 | 59 |
| 60 Fragment mainFragment; | 60 Fragment mainFragment; |
| 61 | 61 |
| 62 Registry(this._compiler); | 62 Registry(this._compiler); |
| 63 | 63 |
| 64 bool get _isProgramSplit => _deferredLoadTask.isProgramSplit; | 64 bool get _isProgramSplit => _deferredLoadTask.isProgramSplit; |
| 65 OutputUnit get _mainOutputUnit => _deferredLoadTask.mainOutputUnit; | 65 OutputUnit get _mainOutputUnit => _deferredLoadTask.mainOutputUnit; |
| 66 | 66 |
| 67 Fragment _computeTargetFragment(Element element) { | 67 Fragment _mapUnitToFragment(OutputUnit targetUnit) { |
| 68 if (mainFragment == null) { | 68 if (mainFragment == null) { |
| 69 mainFragment = new Fragment.main(_deferredLoadTask.mainOutputUnit); | 69 mainFragment = new Fragment.main(_deferredLoadTask.mainOutputUnit); |
| 70 } | 70 } |
| 71 if (!_isProgramSplit) return mainFragment; | 71 if (!_isProgramSplit) { |
| 72 OutputUnit targetUnit = _deferredLoadTask.outputUnitForElement(element); | 72 assert(targetUnit == _deferredLoadTask.mainOutputUnit); |
| 73 return mainFragment; |
| 74 } |
| 73 if (targetUnit == _mainOutputUnit) return mainFragment; | 75 if (targetUnit == _mainOutputUnit) return mainFragment; |
| 74 String name = targetUnit.name; | 76 String name = targetUnit.name; |
| 75 return _deferredFragmentsMap.putIfAbsent( | 77 return _deferredFragmentsMap.putIfAbsent( |
| 76 targetUnit, () => new Fragment.deferred(targetUnit, name)); | 78 targetUnit, () => new Fragment.deferred(targetUnit, name)); |
| 77 } | 79 } |
| 78 | 80 |
| 79 /// Adds the element to the list of elements of the library in the right | 81 /// Adds all elements to their respective libraries in the correct fragment. |
| 80 /// fragment. | 82 void registerElements(OutputUnit outputUnit, List<Element> elements) { |
| 81 void registerElement(Element element) { | 83 Fragment targetFragment = _mapUnitToFragment(outputUnit); |
| 82 _computeTargetFragment(element).add(element.library, element); | 84 for (Element element in Elements.sortedByPosition(elements)) { |
| 85 targetFragment.add(element.library, element); |
| 86 } |
| 83 } | 87 } |
| 84 | 88 |
| 85 Holder registerHolder(String name) { | 89 Holder registerHolder(String name) { |
| 86 return _holdersMap.putIfAbsent( | 90 return _holdersMap.putIfAbsent( |
| 87 name, | 91 name, |
| 88 () => new Holder(name, _holdersMap.length)); | 92 () => new Holder(name, _holdersMap.length)); |
| 89 } | 93 } |
| 90 } | 94 } |
| OLD | NEW |