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

Unified Diff: pkg/barback/lib/src/phase.dart

Issue 18650004: Make Assets know their ID. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: pkg/barback/lib/src/phase.dart
diff --git a/pkg/barback/lib/src/phase.dart b/pkg/barback/lib/src/phase.dart
index d52ed7578597c19bde4f1392e3305af4958ba0f9..b26230b6ac16b2220185aebd805e5beba3fb7721 100644
--- a/pkg/barback/lib/src/phase.dart
+++ b/pkg/barback/lib/src/phase.dart
@@ -69,7 +69,7 @@ class Phase {
///
/// This marks any affected [transforms] as dirty or discards them if their
/// inputs are removed.
- void updateInputs(Map<AssetId, Asset> updated, Set<AssetId> removed) {
+ void updateInputs(Set<Asset> updated, Set<AssetId> removed) {
// Remove any nodes that are no longer being output. Handle removals first
// in case there are assets that were removed by one transform but updated
// by another. In that case, the update should win.
@@ -83,15 +83,18 @@ class Phase {
}
// Update and new or modified assets.
- updated.forEach((id, asset) {
- var node = inputs.putIfAbsent(id, () => new AssetNode(id));
-
- // If it's a new node, remember that so we can see if any new transforms
- // will consume it.
- if (node.asset == null) _newInputs.add(node);
-
- node.updateAsset(asset);
- });
+ for (var asset in updated) {
+ var node = inputs[asset.id];
+ if (node == null) {
+ // It's a new node. Add it and remember it so we can see if any new
+ // transforms will consume it.
+ node = new AssetNode(asset);
+ inputs[asset.id] = node;
+ _newInputs.add(node);
+ } else {
+ node.updateAsset(asset);
+ }
+ }
}
/// Processes this phase.
@@ -119,7 +122,7 @@ class Phase {
for (var transformer in _transformers) {
// TODO(rnystrom): Catch all errors from isPrimary() and redirect
// to results.
- futures.add(transformer.isPrimary(node.id).then((isPrimary) {
+ futures.add(transformer.isPrimary(node.asset).then((isPrimary) {
if (!isPrimary) return;
var transform = new TransformNode(this, transformer, node);
node.consumers.add(transform);
@@ -145,23 +148,25 @@ class Phase {
// Collect all of the outputs. Since the transforms are run in parallel,
// we have to be careful here to ensure that the result is deterministic
// and not influenced by the order that transforms complete.
- var updated = new Map<AssetId, Asset>();
+ var updated = new Set<Asset>();
+ var updatedIds = new Set<AssetId>();
nweiz 2013/07/03 20:08:25 Another good place for AssetSet.
Bob Nystrom 2013/07/03 22:32:11 Done.
var removed = new Set<AssetId>();
var collisions = new Set<AssetId>();
// Handle the generated outputs of all transforms first.
for (var outputs in transformOutputs) {
// Collect the outputs of all transformers together.
- outputs.updated.forEach((id, asset) {
- if (updated.containsKey(id)) {
+ for (var asset in outputs.updated) {
+ if (updatedIds.contains(asset.id)) {
// Report a collision.
- collisions.add(id);
+ collisions.add(asset.id);
} else {
// TODO(rnystrom): In the case of a collision, the asset that
// "wins" is chosen non-deterministically. Do something better.
- updated[id] = asset;
+ updated.add(asset);
+ updatedIds.add(asset.id);
}
- });
+ }
// Track any assets no longer output by this transform. We don't
// handle the case where *another* transform generates the asset

Powered by Google App Engine
This is Rietveld 408576698