| 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>>`. |
| 11 class Fragment { | 11 class Fragment { |
| 12 final Map<LibraryElement, List<Element>> _mapping = | 12 final Map<LibraryElement, List<Element>> _mapping = |
| 13 <LibraryElement, List<Element>>{}; | 13 <LibraryElement, List<Element>>{}; |
| 14 | 14 |
| 15 // It is very common to access the same library multiple times in a row, so | 15 // It is very common to access the same library multiple times in a row, so |
| 16 // we cache the last access. | 16 // we cache the last access. |
| 17 LibraryElement _lastLibrary; | 17 LibraryElement _lastLibrary; |
| 18 List<Element> _lastElements; | 18 List<Element> _lastElements; |
| 19 | 19 |
| 20 /// A unique name representing this fragment. | 20 /// A unique name representing this fragment. |
| 21 final String name; | 21 final String name; |
| 22 final OutputUnit outputUnit; | 22 final OutputUnit outputUnit; |
| 23 | 23 |
| 24 Fragment.main(this.outputUnit) : name = ""; | 24 Fragment.main(this.outputUnit) : name = ""; |
| 25 Fragment.deferred(this.outputUnit, this.name); | 25 |
| 26 Fragment.deferred(this.outputUnit, this.name) { |
| 27 assert(name != ""); |
| 28 } |
| 26 | 29 |
| 27 void add(LibraryElement library, Element element) { | 30 void add(LibraryElement library, Element element) { |
| 28 if (_lastLibrary != library) { | 31 if (_lastLibrary != library) { |
| 29 _lastLibrary = library; | 32 _lastLibrary = library; |
| 30 _lastElements = _mapping.putIfAbsent(library, () => <Element>[]); | 33 _lastElements = _mapping.putIfAbsent(library, () => <Element>[]); |
| 31 } | 34 } |
| 32 _lastElements.add(element); | 35 _lastElements.add(element); |
| 33 } | 36 } |
| 34 | 37 |
| 35 int get length => _mapping.length; | 38 int get length => _mapping.length; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 targetFragment.add(element.library, element); | 88 targetFragment.add(element.library, element); |
| 86 } | 89 } |
| 87 } | 90 } |
| 88 | 91 |
| 89 Holder registerHolder(String name) { | 92 Holder registerHolder(String name) { |
| 90 return _holdersMap.putIfAbsent( | 93 return _holdersMap.putIfAbsent( |
| 91 name, | 94 name, |
| 92 () => new Holder(name, _holdersMap.length)); | 95 () => new Holder(name, _holdersMap.length)); |
| 93 } | 96 } |
| 94 } | 97 } |
| OLD | NEW |