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 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 Fragment.deferred(this.outputUnit, this.name); |
|
kasperl
2014/10/17 06:47:04
Assert that name isn't empty?
floitsch
2014/10/17 09:25:56
Done.
| |
| 26 | 26 |
| 27 bool get isMainFragment => name == ""; | |
|
kasperl
2014/10/17 06:47:04
I guess this is more convenient than asking the re
floitsch
2014/10/17 09:25:56
Since we already have the field in the registry I
| |
| 28 | |
| 27 void add(LibraryElement library, Element element) { | 29 void add(LibraryElement library, Element element) { |
| 28 if (_lastLibrary != library) { | 30 if (_lastLibrary != library) { |
| 29 _lastLibrary = library; | 31 _lastLibrary = library; |
| 30 _lastElements = _mapping.putIfAbsent(library, () => <Element>[]); | 32 _lastElements = _mapping.putIfAbsent(library, () => <Element>[]); |
| 31 } | 33 } |
| 32 _lastElements.add(element); | 34 _lastElements.add(element); |
| 33 } | 35 } |
| 34 | 36 |
| 35 int get length => _mapping.length; | 37 int get length => _mapping.length; |
| 36 | 38 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 targetFragment.add(element.library, element); | 87 targetFragment.add(element.library, element); |
| 86 } | 88 } |
| 87 } | 89 } |
| 88 | 90 |
| 89 Holder registerHolder(String name) { | 91 Holder registerHolder(String name) { |
| 90 return _holdersMap.putIfAbsent( | 92 return _holdersMap.putIfAbsent( |
| 91 name, | 93 name, |
| 92 () => new Holder(name, _holdersMap.length)); | 94 () => new Holder(name, _holdersMap.length)); |
| 93 } | 95 } |
| 94 } | 96 } |
| OLD | NEW |