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

Unified Diff: lib/src/system_cache.dart

Issue 2079303003: Track Source objects in PackageNames. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Code review changes Created 4 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
« no previous file with comments | « lib/src/source_registry.dart ('k') | lib/src/validator/dependency.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/system_cache.dart
diff --git a/lib/src/system_cache.dart b/lib/src/system_cache.dart
index 50440de3c10b61a987e6575d9a657767db44a120..dd5b88cb6775c16e546c10c3e457cb046221871c 100644
--- a/lib/src/system_cache.dart
+++ b/lib/src/system_cache.dart
@@ -47,19 +47,20 @@ class SystemCache {
final sources = new SourceRegistry();
/// The sources bound to this cache.
- final _boundSources = <String, BoundSource>{};
+ final _boundSources = <Source, BoundSource>{};
/// The built-in Git source bound to this cache.
- BoundGitSource get git => _boundSources["git"] as BoundGitSource;
+ BoundGitSource get git => _boundSources[sources.git] as BoundGitSource;
/// The built-in hosted source bound to this cache.
- BoundHostedSource get hosted => _boundSources["hosted"] as BoundHostedSource;
+ BoundHostedSource get hosted =>
+ _boundSources[sources.hosted] as BoundHostedSource;
/// The built-in path source bound to this cache.
- BoundPathSource get path => _boundSources["path"] as BoundPathSource;
+ BoundPathSource get path => _boundSources[sources.path] as BoundPathSource;
/// The default source bound to this cache.
- BoundSource get defaultSource => source(null);
+ BoundSource get defaultSource => source(sources[null]);
/// Creates a system cache and registers all sources in [sources].
///
@@ -69,31 +70,27 @@ class SystemCache {
: rootDir = rootDir == null ? SystemCache.defaultDir : rootDir {
for (var source in sources.all) {
if (source is HostedSource) {
- _boundSources[source.name] = source.bind(this, isOffline: isOffline);
+ _boundSources[source] = source.bind(this, isOffline: isOffline);
} else {
- _boundSources[source.name] = source.bind(this);
+ _boundSources[source] = source.bind(this);
}
}
}
- /// Returns the source named [name] bound to this cache.
- ///
- /// Returns a bound version of [UnknownSource] if no source with that name has
- /// been registered. If [name] is null, returns the default source.
- BoundSource source(String name) =>
- _boundSources.putIfAbsent(name, () => sources[name].bind(this));
+ /// Returns the version of [source] bound to this cache.
+ BoundSource source(Source source) =>
+ _boundSources.putIfAbsent(source, () => source.bind(this));
/// Loads the package identified by [id].
///
/// Throws an [ArgumentError] if [id] has an invalid source.
Package load(PackageId id) {
- var source = this.source(id.source);
- if (source.source is UnknownSource) {
+ if (id.source is UnknownSource) {
throw new ArgumentError("Unknown source ${id.source}.");
}
- var dir = source.getDirectory(id);
- return new Package.load(id.name, dir, sources);
+ return new Package.load(
+ id.name, source(id.source).getDirectory(id), sources);
}
/// Determines if the system cache contains the package identified by [id].
« no previous file with comments | « lib/src/source_registry.dart ('k') | lib/src/validator/dependency.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698