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

Unified Diff: pkg/front_end/lib/src/base/file_repository.dart

Issue 2643033003: Clean up hacky handling of "dart:" URIs in incremental resolved AST generator. (Closed)
Patch Set: Created 3 years, 11 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 | pkg/front_end/lib/src/incremental_resolved_ast_generator_impl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/lib/src/base/file_repository.dart
diff --git a/pkg/front_end/lib/src/base/file_repository.dart b/pkg/front_end/lib/src/base/file_repository.dart
index 48223e89030dfdb58a6a5cebbc83552292a16bd9..d4d4f7cb6885ddb679264df67cf4e8e8ced3bcd1 100644
--- a/pkg/front_end/lib/src/base/file_repository.dart
+++ b/pkg/front_end/lib/src/base/file_repository.dart
@@ -16,7 +16,7 @@ class FileRepository {
final _uris = <Uri>[];
/// Map from a URI to its index in [_uris].
- final _indexForUri = <Uri, int>{};
+ final _uriToIndexMap = <Uri, int>{};
/// The file contents associated with the URIs in [_uris].
final _contents = <String>[];
@@ -54,26 +54,19 @@ class FileRepository {
/// Return the arbitrary path associated with [uri].
///
- /// The uri must have previously been passed to [store].
- String pathForUri(Uri uri) {
- int index = _indexForUri[uri];
- assert(index != null);
- return _pathForIndex(index);
+ /// If [allocate] is `false` (the default), the uri must have previously been
+ /// allocated a corresponding path, e.g. via a call to [store]. If [allocate]
+ /// is `true`, then a new path will be allocated if necessary.
+ String pathForUri(Uri uri, {bool allocate: false}) {
+ return _pathForIndex(_indexForUri(uri, allocate));
}
/// Associate the given [uri] with file [contents].
///
/// The arbitrary path associated with the file is returned.
String store(Uri uri, String contents) {
- int index = _indexForUri[uri];
- if (index == null) {
- index = _uris.length;
- _uris.add(uri);
- _indexForUri[uri] = index;
- _contents.add(contents);
- } else {
- _contents[index] = contents;
- }
+ int index = _indexForUri(uri, true);
+ _contents[index] = contents;
return _pathForIndex(index);
}
@@ -90,6 +83,18 @@ class FileRepository {
return int.parse(path.substring(1, path.length - 5));
}
+ int _indexForUri(Uri uri, bool allocate) {
+ int index = _uriToIndexMap[uri];
+ assert(allocate || index != null);
+ if (index == null) {
+ index = _uris.length;
+ _uris.add(uri);
+ _uriToIndexMap[uri] = index;
+ _contents.add(null);
+ }
+ return index;
+ }
+
/// Return the arbitrary path associated with the given index.
String _pathForIndex(int index) => '/$index.dart';
}
« no previous file with comments | « no previous file | pkg/front_end/lib/src/incremental_resolved_ast_generator_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698