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

Unified Diff: pkg/analysis_server/lib/src/domains/analysis/occurrences.dart

Issue 1338153002: Merge occurrences. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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/analysis_server/test/plugin/set_analysis_domain_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/domains/analysis/occurrences.dart
diff --git a/pkg/analysis_server/lib/src/domains/analysis/occurrences.dart b/pkg/analysis_server/lib/src/domains/analysis/occurrences.dart
index 561693e3bbc2292a3875f1d57a20ea571dca61c4..f0a9a1cda29f7a8e9934fe35a031042788f8c1ec 100644
--- a/pkg/analysis_server/lib/src/domains/analysis/occurrences.dart
+++ b/pkg/analysis_server/lib/src/domains/analysis/occurrences.dart
@@ -36,10 +36,25 @@ OccurrencesCollectorImpl computeOccurrences(
* A concrete implementation of [OccurrencesCollector].
*/
class OccurrencesCollectorImpl implements OccurrencesCollector {
- final List<protocol.Occurrences> allOccurrences = <protocol.Occurrences>[];
+ Map<protocol.Element, protocol.Occurrences> elementOccurrences =
+ <protocol.Element, protocol.Occurrences>{};
+
+ List<protocol.Occurrences> get allOccurrences {
+ return elementOccurrences.values.toList();
+ }
@override
- void addOccurrences(protocol.Occurrences occurrences) {
- allOccurrences.add(occurrences);
+ void addOccurrences(protocol.Occurrences current) {
+ protocol.Element element = current.element;
+ protocol.Occurrences existing = elementOccurrences[element];
+ if (existing != null) {
+ List<int> offsets = _merge(existing.offsets, current.offsets);
+ current = new protocol.Occurrences(element, offsets, existing.length);
+ }
+ elementOccurrences[element] = current;
+ }
+
+ static List<int> _merge(List<int> a, List<int> b) {
+ return <int>[]..addAll(a)..addAll(b);
}
}
« no previous file with comments | « no previous file | pkg/analysis_server/test/plugin/set_analysis_domain_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698