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

Unified Diff: pkg/front_end/lib/src/incremental/file_state.dart

Issue 2937103002: Cache transitive files in FileState. (Closed)
Patch Set: Created 3 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 | « no previous file | pkg/front_end/test/src/incremental/file_state_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/lib/src/incremental/file_state.dart
diff --git a/pkg/front_end/lib/src/incremental/file_state.dart b/pkg/front_end/lib/src/incremental/file_state.dart
index 77f4d147e9e0bef8a2fc845c5f2eae8eff67cb6f..27519429b9cdec9baac03341800fad37ca8b796d 100644
--- a/pkg/front_end/lib/src/incremental/file_state.dart
+++ b/pkg/front_end/lib/src/incremental/file_state.dart
@@ -49,6 +49,7 @@ class FileState {
Set<FileState> _directReferencedFiles = new Set<FileState>();
List<FileState> _directReferencedLibraries = <FileState>[];
+ Set<FileState> _transitiveFiles;
/// This flag is set to `true` during the mark phase of garbage collection
/// and set back to `false` for survived instances.
@@ -106,17 +107,18 @@ class FileState {
/// Return the set of transitive files - the file itself and all of the
/// directly or indirectly referenced files.
Set<FileState> get transitiveFiles {
- // TODO(scheglov) add caching.
- var transitiveFiles = new Set<FileState>();
+ if (_transitiveFiles == null) {
+ _transitiveFiles = new Set<FileState>();
- void appendReferenced(FileState file) {
- if (transitiveFiles.add(file)) {
- file._directReferencedFiles.forEach(appendReferenced);
+ void appendReferenced(FileState file) {
+ if (_transitiveFiles.add(file)) {
+ file._directReferencedFiles.forEach(appendReferenced);
+ }
}
- }
- appendReferenced(this);
- return transitiveFiles;
+ appendReferenced(this);
+ }
+ return _transitiveFiles;
}
@override
@@ -191,6 +193,7 @@ class FileState {
}
// Compute referenced files.
+ var oldDirectReferencedFiles = _directReferencedFiles;
_directReferencedFiles = new Set<FileState>()
..addAll(_importedLibraries)
..addAll(_exportedLibraries)
@@ -199,6 +202,19 @@ class FileState {
..addAll(_importedLibraries)
..addAll(_exportedLibraries))
.toList();
+
+ // If the set of directly referenced files of this file is changed,
+ // then the transitive sets of files that include this file are also
+ // changed. Reset these transitive sets.
+ if (_directReferencedFiles.length != oldDirectReferencedFiles.length ||
+ !_directReferencedFiles.containsAll(oldDirectReferencedFiles)) {
+ for (var file in _fsState._uriToFile.values) {
+ if (file._transitiveFiles != null &&
+ file._transitiveFiles.contains(this)) {
+ file._transitiveFiles = null;
+ }
+ }
+ }
}
@override
« no previous file with comments | « no previous file | pkg/front_end/test/src/incremental/file_state_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698