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

Unified Diff: pkg/analyzer/lib/src/context/cache.dart

Issue 1151563004: Optimize AnalysisContext.getSourcesWithFullName(). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: rebase Created 5 years, 7 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/analyzer/lib/src/context/context.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/context/cache.dart
diff --git a/pkg/analyzer/lib/src/context/cache.dart b/pkg/analyzer/lib/src/context/cache.dart
index fc188ba1ec20ce9f7213c8b3c7536cac67adc211..4c8e9042854d7ddaff327de2c66b319194f84416 100644
--- a/pkg/analyzer/lib/src/context/cache.dart
+++ b/pkg/analyzer/lib/src/context/cache.dart
@@ -111,6 +111,19 @@ class AnalysisCache {
}
/**
+ * Return [Source]s whose full path is equal to the given [path].
+ * Maybe empty, but not `null`.
+ */
+ List<Source> getSourcesWithFullName(String path) {
+ List<Source> sources = <Source>[];
+ for (CachePartition partition in _partitions) {
+ List<Source> partitionSources = partition.getSourcesWithFullName(path);
+ sources.addAll(partitionSources);
+ }
+ return sources;
+ }
+
+ /**
* Return the state of the given [result] for the given [target].
*
* It does not update the cache, if the corresponding [CacheEntry] does not
@@ -728,6 +741,11 @@ abstract class CachePartition {
final HashSet<Source> _sources = new HashSet<Source>();
/**
+ * A table mapping full paths to lists of [Source]s with these full paths.
+ */
+ final Map<String, List<Source>> _pathToSources = <String, List<Source>>{};
+
+ /**
* Initialize a newly created cache partition, belonging to the given
* [context].
*/
@@ -748,6 +766,15 @@ abstract class CachePartition {
CacheEntry get(AnalysisTarget target) => _targetMap[target];
/**
+ * Return [Source]s whose full path is equal to the given [path].
+ * Maybe empty, but not `null`.
+ */
+ List<Source> getSourcesWithFullName(String path) {
+ List<Source> sources = _pathToSources[path];
+ return sources != null ? sources : Source.EMPTY_LIST;
+ }
+
+ /**
* Return `true` if this partition is responsible for the given [target].
*/
bool isResponsibleFor(AnalysisTarget target);
@@ -827,6 +854,10 @@ abstract class CachePartition {
void _addIfSource(AnalysisTarget target) {
if (target is Source) {
_sources.add(target);
+ {
+ String fullName = target.fullName;
+ _pathToSources.putIfAbsent(fullName, () => <Source>[]).add(target);
+ }
}
}
@@ -858,6 +889,16 @@ abstract class CachePartition {
void _removeIfSource(AnalysisTarget target) {
if (target is Source) {
_sources.remove(target);
+ {
+ String fullName = target.fullName;
+ List<Source> sources = _pathToSources[fullName];
+ if (sources != null) {
+ sources.remove(target);
+ if (sources.isEmpty) {
+ _pathToSources.remove(fullName);
+ }
+ }
+ }
}
}
}
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/context/context.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698