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

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

Issue 739643003: Cache ElementLocation instance and index key/location ids. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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/generated/element.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/services/index/store/codec.dart
diff --git a/pkg/analysis_server/lib/src/services/index/store/codec.dart b/pkg/analysis_server/lib/src/services/index/store/codec.dart
index b06ec563bb8dead4a416139a0ee543a88d26f50d..de900568c23297c7f22a847351d3d91f8b7d3e91 100644
--- a/pkg/analysis_server/lib/src/services/index/store/codec.dart
+++ b/pkg/analysis_server/lib/src/services/index/store/codec.dart
@@ -104,13 +104,35 @@ class ElementCodec {
* file paths instead of [Element] location URIs.
*/
int encode(Element element, bool forKey) {
- List<int> path = _getLocationPath(element, forKey);
- int index = _pathToIndex[path];
- if (index == null) {
- index = _indexToPath.length;
- _pathToIndex[path] = index;
- _indexToPath.add(path);
+ ElementLocationImpl location = element.location;
+ // check the location has a cached id
+ if (!identical(location.indexOwner, this)) {
+ location.indexKeyId = null;
+ location.indexLocationId = null;
+ }
+ if (forKey) {
+ int id = location.indexKeyId;
+ if (id != null) {
+ return id;
+ }
+ } else {
+ int id = location.indexLocationId;
+ if (id != null) {
+ return id;
+ }
+ }
+ // prepare an id
+ List<int> path = _getLocationPath(element, location, forKey);
+ int index = _encodePath(path);
+ // put the id into the location
+ if (forKey) {
+ location.indexOwner = this;
+ location.indexKeyId = index;
+ } else {
+ location.indexOwner = this;
+ location.indexLocationId = index;
}
+ // done
return index;
}
@@ -119,6 +141,11 @@ class ElementCodec {
*/
int encodeHash(Element element) {
List<int> path = _getLocationPathLimited(element);
+ int index = _encodePath(path);
+ return index;
+ }
+
+ int _encodePath(List<int> path) {
int index = _pathToIndex[path];
if (index == null) {
index = _indexToPath.length;
@@ -146,12 +173,14 @@ class ElementCodec {
/**
* If [usePath] is `true` then [Source] path should be used instead of URI.
*/
- List<int> _getLocationPath(Element element, bool usePath) {
+ List<int> _getLocationPath(Element element, ElementLocation location,
+ bool usePath) {
// prepare the location components
- List<String> components = element.location.components;
+ List<String> components = location.components;
if (usePath) {
LibraryElement library = element.library;
if (library != null) {
+ components = components.toList();
components[0] = library.source.fullName;
if (element.enclosingElement is CompilationUnitElement) {
components[1] = library.definingCompilationUnit.source.fullName;
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/element.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698