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

Side by Side Diff: pkg/barback/lib/src/phase.dart

Issue 26598002: Track the original assets more efficiently in Phase. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 barback.phase; 5 library barback.phase;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'asset_cascade.dart'; 10 import 'asset_cascade.dart';
11 import 'asset_id.dart'; 11 import 'asset_id.dart';
12 import 'asset_node.dart'; 12 import 'asset_node.dart';
13 import 'asset_set.dart'; 13 import 'asset_set.dart';
14 import 'group_runner.dart'; 14 import 'group_runner.dart';
15 import 'errors.dart'; 15 import 'errors.dart';
16 import 'multi_set.dart';
16 import 'phase_forwarder.dart'; 17 import 'phase_forwarder.dart';
17 import 'phase_input.dart'; 18 import 'phase_input.dart';
18 import 'phase_output.dart'; 19 import 'phase_output.dart';
19 import 'stream_pool.dart'; 20 import 'stream_pool.dart';
20 import 'transformer.dart'; 21 import 'transformer.dart';
21 import 'transformer_group.dart'; 22 import 'transformer_group.dart';
22 import 'utils.dart'; 23 import 'utils.dart';
23 24
24 /// One phase in the ordered series of transformations in an [AssetCascade]. 25 /// One phase in the ordered series of transformations in an [AssetCascade].
25 /// 26 ///
(...skipping 24 matching lines...) Expand all
50 /// For the first phase, these will be the source assets. For all other 51 /// For the first phase, these will be the source assets. For all other
51 /// phases, they will be the outputs from the previous phase. 52 /// phases, they will be the outputs from the previous phase.
52 final _inputs = new Map<AssetId, PhaseInput>(); 53 final _inputs = new Map<AssetId, PhaseInput>();
53 54
54 /// The forwarders for this phase. 55 /// The forwarders for this phase.
55 final _forwarders = new Map<AssetId, PhaseForwarder>(); 56 final _forwarders = new Map<AssetId, PhaseForwarder>();
56 57
57 /// The outputs for this phase. 58 /// The outputs for this phase.
58 final _outputs = new Map<AssetId, PhaseOutput>(); 59 final _outputs = new Map<AssetId, PhaseOutput>();
59 60
60 // TODO(nweiz): Don't re-calculate this on the fly all the time.
61 /// The set of all [AssetNode.origin] properties of the input assets for this 61 /// The set of all [AssetNode.origin] properties of the input assets for this
62 /// phase. 62 /// phase.
63 /// 63 ///
64 /// This is used to determine which assets have been passed unmodified through 64 /// This is used to determine which assets have been passed unmodified through
65 /// [_inputs] or [_groups]. Each input asset has a PhaseInput in [_inputs]. If 65 /// [_inputs] or [_groups]. Each input asset has a PhaseInput in [_inputs]. If
66 /// that input isn't consumed by any transformers, it will be forwarded 66 /// that input isn't consumed by any transformers, it will be forwarded
67 /// through the PhaseInput. However, it's possible that it was consumed by a 67 /// through the PhaseInput. However, it's possible that it was consumed by a
68 /// group, and so shouldn't be forwarded through the phase as a whole. 68 /// group, and so shouldn't be forwarded through the phase as a whole.
69 /// 69 ///
70 /// In order to detect whether an output has been forwarded through a group or 70 /// In order to detect whether an output has been forwarded through a group or
71 /// a PhaseInput, we must be able to distinguish it from other outputs with 71 /// a PhaseInput, we must be able to distinguish it from other outputs with
72 /// the same id. To do so, we check if its origin is in [_inputOrigins]. If 72 /// the same id. To do so, we check if its origin is in [_inputOrigins]. If
73 /// so, it's been forwarded unmodified. 73 /// so, it's been forwarded unmodified.
74 Set<AssetNode> get _inputOrigins => 74 final _inputOrigins = new MultiSet<AssetNode>();
75 _inputs.values.map((input) => input.input.origin).toSet();
76 75
77 /// A stream that emits an event whenever this phase becomes dirty and needs 76 /// A stream that emits an event whenever this phase becomes dirty and needs
78 /// to be run. 77 /// to be run.
79 /// 78 ///
80 /// This may emit events when the phase was already dirty or while processing 79 /// This may emit events when the phase was already dirty or while processing
81 /// transforms. Events are emitted synchronously to ensure that the dirty 80 /// transforms. Events are emitted synchronously to ensure that the dirty
82 /// state is thoroughly propagated as soon as any assets are changed. 81 /// state is thoroughly propagated as soon as any assets are changed.
83 Stream get onDirty => _onDirtyPool.stream; 82 Stream get onDirty => _onDirtyPool.stream;
84 final _onDirtyPool = new StreamPool.broadcast(); 83 final _onDirtyPool = new StreamPool.broadcast();
85 84
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 // there's one additional channel for the non-grouped transformers. 135 // there's one additional channel for the non-grouped transformers.
137 var forwarder = new PhaseForwarder(_groups.length + 1); 136 var forwarder = new PhaseForwarder(_groups.length + 1);
138 _forwarders[node.id] = forwarder; 137 _forwarders[node.id] = forwarder;
139 forwarder.onForwarding.listen((asset) { 138 forwarder.onForwarding.listen((asset) {
140 _addOutput(asset); 139 _addOutput(asset);
141 140
142 var exception = _outputs[asset.id].collisionException; 141 var exception = _outputs[asset.id].collisionException;
143 if (exception != null) cascade.reportError(exception); 142 if (exception != null) cascade.reportError(exception);
144 }); 143 });
145 144
145 _inputOrigins.add(node.origin);
146 var input = new PhaseInput(this, node, _transformers); 146 var input = new PhaseInput(this, node, _transformers);
147 _inputs[node.id] = input; 147 _inputs[node.id] = input;
148 input.input.whenRemoved.then((_) { 148 input.input.whenRemoved.then((_) {
149 _inputOrigins.remove(node.origin);
149 _inputs.remove(node.id); 150 _inputs.remove(node.id);
150 _forwarders.remove(node.id).remove(); 151 _forwarders.remove(node.id).remove();
151 }); 152 });
152 _onDirtyPool.add(input.onDirty); 153 _onDirtyPool.add(input.onDirty);
153 _onDirtyController.add(null); 154 _onDirtyController.add(null);
154 155
155 for (var group in _groups.values) { 156 for (var group in _groups.values) {
156 group.addInput(node); 157 group.addInput(node);
157 } 158 }
158 } 159 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 _outputs[asset.id].add(asset); 300 _outputs[asset.id].add(asset);
300 } else { 301 } else {
301 _outputs[asset.id] = new PhaseOutput(this, asset); 302 _outputs[asset.id] = new PhaseOutput(this, asset);
302 _outputs[asset.id].onAsset.listen((output) { 303 _outputs[asset.id].onAsset.listen((output) {
303 if (_next != null) _next.addInput(output); 304 if (_next != null) _next.addInput(output);
304 }, onDone: () => _outputs.remove(asset.id)); 305 }, onDone: () => _outputs.remove(asset.id));
305 if (_next != null) _next.addInput(_outputs[asset.id].output); 306 if (_next != null) _next.addInput(_outputs[asset.id].output);
306 } 307 }
307 } 308 }
308 } 309 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698