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

Unified Diff: pkg/analysis_services/lib/src/index/store/codec.dart

Issue 399723003: Improve Dart master index selectivity. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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_services/lib/src/index/store/split_store.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_services/lib/src/index/store/codec.dart
diff --git a/pkg/analysis_services/lib/src/index/store/codec.dart b/pkg/analysis_services/lib/src/index/store/codec.dart
index 108f93672ee5deeabab0eef3cc892a964d60a9c8..a49b9efa852355892a1bd78251409234f9d39942 100644
--- a/pkg/analysis_services/lib/src/index/store/codec.dart
+++ b/pkg/analysis_services/lib/src/index/store/codec.dart
@@ -6,10 +6,10 @@ library services.src.index.store.codec;
import 'dart:collection';
+import 'package:analysis_services/index/index.dart';
+import 'package:analysis_services/src/index/store/collection.dart';
import 'package:analyzer/src/generated/element.dart';
import 'package:analyzer/src/generated/engine.dart';
-import 'package:analysis_services/src/index/store/collection.dart';
-import 'package:analysis_services/index/index.dart';
/**
@@ -110,6 +110,20 @@ class ElementCodec {
return index;
}
+ /**
+ * Returns an integer that corresponds to an approximated location of the given {@link Element}.
+ */
+ int encodeHash(Element element) {
+ List<int> path = _getLocationPathLimited(element);
+ int index = _pathToIndex[path];
+ if (index == null) {
+ index = _indexToPath.length;
+ _pathToIndex[path] = index;
+ _indexToPath.add(path);
+ }
+ return index;
+ }
+
List<String> _getLocationComponents(List<int> path) {
int length = path.length;
List<String> components = new List<String>();
@@ -152,6 +166,21 @@ class ElementCodec {
}
}
+ /**
+ * Returns an approximation of the given {@link Element}'s location.
+ */
+ List<int> _getLocationPathLimited(Element element) {
+ List<String> components = element.location.components;
+ int length = components.length;
+ String firstComponent = components[0];
+ String lastComponent = components[length - 1];
+ firstComponent = firstComponent.substring(1);
+ lastComponent = _substringBeforeAt(lastComponent);
+ int firstId = _stringCodec.encode(firstComponent);
+ int lastId = _stringCodec.encode(lastComponent);
+ return <int>[firstId, lastId];
+ }
+
bool _hasLocalOffset(List<String> components) {
for (String component in components) {
if (component.indexOf('@') != -1) {
@@ -160,6 +189,14 @@ class ElementCodec {
}
return false;
}
+
+ String _substringBeforeAt(String str) {
+ int atOffset = str.indexOf('@');
+ if (atOffset != -1) {
+ str = str.substring(0, atOffset);
+ }
+ return str;
+ }
}
« no previous file with comments | « no previous file | pkg/analysis_services/lib/src/index/store/split_store.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698