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

Unified Diff: sdk/lib/_internal/pub_generated/lib/src/solver/dependency_queue.dart

Issue 557563002: Store the async-await compiled pub code directly in the repo. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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: sdk/lib/_internal/pub_generated/lib/src/solver/dependency_queue.dart
diff --git a/sdk/lib/_internal/pub_generated/lib/src/solver/dependency_queue.dart b/sdk/lib/_internal/pub_generated/lib/src/solver/dependency_queue.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f2651f4f6b3c4d6c5e1740aaa7dbc36a3d5f3f73
--- /dev/null
+++ b/sdk/lib/_internal/pub_generated/lib/src/solver/dependency_queue.dart
@@ -0,0 +1,73 @@
+library pub.solver.dependency_queue;
+import 'dart:async';
+import 'dart:collection' show Queue;
+import '../log.dart' as log;
+import '../package.dart';
+import 'backtracking_solver.dart';
+class DependencyQueue {
+ final BacktrackingSolver _solver;
+ final Queue<PackageDep> _presorted;
+ final List<PackageDep> _remaining;
+ bool _isSorted = false;
+ bool get isEmpty => _presorted.isEmpty && _remaining.isEmpty;
+ Future _sortFuture;
+ factory DependencyQueue(BacktrackingSolver solver, Iterable<PackageDep> deps)
+ {
+ var presorted = <PackageDep>[];
+ var remaining = <PackageDep>[];
+ for (var dep in deps) {
+ if (solver.getSelected(dep.name) != null ||
+ solver.getLocked(dep.name) != null) {
+ presorted.add(dep);
+ } else {
+ remaining.add(dep);
+ }
+ }
+ presorted.sort((a, b) => a.name.compareTo(b.name));
+ return new DependencyQueue._(
+ solver,
+ new Queue<PackageDep>.from(presorted),
+ remaining);
+ }
+ DependencyQueue._(this._solver, this._presorted, this._remaining);
+ Future<PackageDep> advance() {
+ if (_presorted.isNotEmpty) {
+ return new Future.value(_presorted.removeFirst());
+ }
+ if (!_isSorted) return _sort().then((_) => _remaining.removeAt(0));
+ return new Future.value(_remaining.removeAt(0));
+ }
+ Future _sort() {
+ assert(_sortFuture == null);
+ _sortFuture = Future.wait(_remaining.map(_getNumVersions)).then((versions) {
+ _sortFuture = null;
+ var versionMap = new Map.fromIterables(_remaining, versions);
+ _remaining.sort((a, b) {
+ if (versionMap[a] != versionMap[b]) {
+ return versionMap[a].compareTo(versionMap[b]);
+ }
+ return a.name.compareTo(b.name);
+ });
+ _isSorted = true;
+ });
+ return _sortFuture;
+ }
+ Future<int> _getNumVersions(PackageDep dep) {
+ if (dep.isRoot) {
+ return new Future.value(1);
+ }
+ return _solver.cache.getVersions(dep.toRef()).then((versions) {
+ for (var rootDep in _solver.root.immediateDependencies) {
+ if (rootDep.name == dep.name) {
+ versions =
+ versions.where((id) => rootDep.constraint.allows(id.version));
+ break;
+ }
+ }
+ return versions.length;
+ }).catchError((error, trace) {
+ log.solver("Could not get versions for $dep:\n$error\n\n$trace");
+ return 0;
+ });
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698