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

Unified Diff: pkg/analyzer/lib/src/dart/analysis/file_state.dart

Issue 2543263002: Use Map(s) for top-level declarations. (Closed)
Patch Set: Created 4 years 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/analyzer/test/src/dart/analysis/file_state_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/dart/analysis/file_state.dart
diff --git a/pkg/analyzer/lib/src/dart/analysis/file_state.dart b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
index ae15012012efb6b525db801c4304aae0248ca03f..509824c1b68a9c0f96a778fb051a48fe0d1fe829 100644
--- a/pkg/analyzer/lib/src/dart/analysis/file_state.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
@@ -101,8 +101,8 @@ class FileState {
Set<FileState> _transitiveFiles;
String _transitiveSignature;
- List<TopLevelDeclaration> _topLevelDeclarations;
- List<TopLevelDeclaration> _exportedTopLevelDeclarations;
+ Map<String, TopLevelDeclaration> _topLevelDeclarations;
+ Map<String, TopLevelDeclaration> _exportedTopLevelDeclarations;
FileState._(this._fsState, this.path, this.uri, this.source);
@@ -135,45 +135,41 @@ class FileState {
/**
* Return [TopLevelDeclaration]s exported from the this library file.
Paul Berry 2016/12/02 16:34:42 Can you update this comment to explain that the ke
*/
- List<TopLevelDeclaration> get exportedTopLevelDeclarations {
+ Map<String, TopLevelDeclaration> get exportedTopLevelDeclarations {
if (_exportedTopLevelDeclarations == null) {
- _exportedTopLevelDeclarations = <TopLevelDeclaration>[];
+ _exportedTopLevelDeclarations = <String, TopLevelDeclaration>{};
Set<FileState> seenLibraries = new Set<FileState>();
/**
* Compute [TopLevelDeclaration]s exported from the [library].
*/
- List<TopLevelDeclaration> computeExported(FileState library) {
+ Map<String, TopLevelDeclaration> computeExported(FileState library) {
var declarations = <String, TopLevelDeclaration>{};
if (seenLibraries.add(library)) {
// Append the library declarations.
- for (TopLevelDeclaration t in library.topLevelDeclarations) {
- declarations[t.name] = t;
- }
+ declarations.addAll(library.topLevelDeclarations);
for (FileState part in library.partedFiles) {
- for (TopLevelDeclaration t in part.topLevelDeclarations) {
- declarations[t.name] = t;
- }
+ declarations.addAll(part.topLevelDeclarations);
}
// Append the exported declarations.
for (int i = 0; i < library._exportedFiles.length; i++) {
- List<TopLevelDeclaration> exported =
+ Map<String, TopLevelDeclaration> exported =
computeExported(library._exportedFiles[i]);
- for (TopLevelDeclaration t in exported) {
+ exported.forEach((String name, TopLevelDeclaration t) {
if (!declarations.containsKey(t.name) &&
Brian Wilkerson 2016/12/02 16:32:17 Somewhat off topic, but if we append the exported
library._exportFilters[i].accepts(t.name)) {
declarations[t.name] = t;
}
- }
+ });
}
// We're done with this library.
seenLibraries.remove(library);
}
- return declarations.values.toList();
+ return declarations;
}
_exportedTopLevelDeclarations = computeExported(this);
@@ -226,13 +222,13 @@ class FileState {
/**
* Return public top-level declarations declared in the file.
Paul Berry 2016/12/02 16:34:42 Ditto
*/
- List<TopLevelDeclaration> get topLevelDeclarations {
+ Map<String, TopLevelDeclaration> get topLevelDeclarations {
if (_topLevelDeclarations == null) {
- _topLevelDeclarations = <TopLevelDeclaration>[];
+ _topLevelDeclarations = <String, TopLevelDeclaration>{};
void addDeclaration(TopLevelDeclarationKind kind, String name) {
if (!name.startsWith('_')) {
- _topLevelDeclarations.add(new TopLevelDeclaration(kind, name));
+ _topLevelDeclarations[name] = new TopLevelDeclaration(kind, name);
}
}
« no previous file with comments | « no previous file | pkg/analyzer/test/src/dart/analysis/file_state_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698