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

Unified Diff: sdk/lib/_internal/pub/lib/src/barback/build_environment.dart

Issue 221333004: Fix a few remaining synchronous uses of BuildDirectory.server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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
« no previous file with comments | « no previous file | sdk/lib/_internal/pub/lib/src/barback/old_web_socket_api.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/pub/lib/src/barback/build_environment.dart
diff --git a/sdk/lib/_internal/pub/lib/src/barback/build_environment.dart b/sdk/lib/_internal/pub/lib/src/barback/build_environment.dart
index 07f3d294360b60adb139566a5c042b95f72cc6b6..1b6c5c5f70cd5cfd7166f522baa7797881ff2ca7 100644
--- a/sdk/lib/_internal/pub/lib/src/barback/build_environment.dart
+++ b/sdk/lib/_internal/pub/lib/src/barback/build_environment.dart
@@ -18,6 +18,7 @@ import '../log.dart' as log;
import '../package.dart';
import '../package_graph.dart';
import '../sdk.dart' as sdk;
+import '../utils.dart';
import 'admin_server.dart';
import 'build_directory.dart';
import 'dart_forwarding_transformer.dart';
@@ -250,8 +251,8 @@ class BuildEnvironment {
/// Look up [assetPath] in the "packages" directory in the entrypoint package.
Future<List<Uri>> _lookUpPathInPackagesDirectory(String assetPath) {
var components = path.split(path.relative(assetPath));
- if (components.first != "packages") return [];
- if (!graph.packages.containsKey(components[1])) return [];
+ if (components.first != "packages") return new Future.value([]);
+ if (!graph.packages.containsKey(components[1])) return new Future.value([]);
return Future.wait(_directories.values.map((dir) {
return dir.server.then((server) =>
server.url.resolveUri(path.toUri(assetPath)));
@@ -281,21 +282,28 @@ class BuildEnvironment {
}));
}
- return [];
+ return new Future.value([]);
}
/// Given a URL to an asset served by this environment, returns the ID of the
/// asset that would be accessed by that URL.
///
- /// If no server can serve [url], returns `null`.
- AssetId getAssetIdForUrl(Uri url) {
- var directory = _directories.values.firstWhere(
- (dir) => dir.server.address.host == url.host &&
- dir.server.port == url.port,
- orElse: () => null);
- if (directory == null) return null;
-
- return directory.server.urlToId(url);
+ /// If no server can serve [url], completes to `null`.
+ Future<AssetId> getAssetIdForUrl(Uri url) {
+ var iterator = _directories.values.toList().iterator;
+ iterate() {
+ if (!iterator.moveNext()) return null;
+
+ return iterator.current.server.then((server) {
+ if (server.address.host == url.host && server.port == url.port) {
+ return server.urlToId(url);
+ } else {
+ return iterate();
+ }
+ });
+ }
+
+ return syncFuture(iterate);
Bob Nystrom 2014/04/02 17:31:31 Optimizing to not short-circuit walking the whole
nweiz 2014/04/02 20:21:27 Done.
}
/// Determines if [sourcePath] is contained within any of the directories in
« no previous file with comments | « no previous file | sdk/lib/_internal/pub/lib/src/barback/old_web_socket_api.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698