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

Unified Diff: pkg/analyzer/lib/src/summary/incremental_cache.dart

Issue 1818823005: Cache library closure hashes and absolute URIs. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/summary/incremental_cache.dart
diff --git a/pkg/analyzer/lib/src/summary/incremental_cache.dart b/pkg/analyzer/lib/src/summary/incremental_cache.dart
index ea9b46fabe7c8f3b3c85a121c552117306fc273b..5211e9e28fa7b555ef3cacd1162647d40e0f80fd 100644
--- a/pkg/analyzer/lib/src/summary/incremental_cache.dart
+++ b/pkg/analyzer/lib/src/summary/incremental_cache.dart
@@ -6,7 +6,6 @@ import 'dart:convert' show UTF8;
import 'dart:core' hide Resource;
import 'package:analyzer/dart/element/element.dart';
-import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/summary/format.dart';
@@ -37,46 +36,6 @@ abstract class CacheStorage {
}
/**
- * A [Folder] based implementation of [CacheStorage].
- */
-class FolderCacheStorage implements CacheStorage {
Paul Berry 2016/03/21 20:29:32 I'm not sure I agree with the idea of removing thi
scheglov 2016/03/21 20:58:26 OK, restored.
- /**
- * The folder to read and write files.
- */
- final Folder folder;
-
- /**
- * To ensure that operations of writing files are atomic we create a temporary
- * file with this name in the [folder] and then rename it once we are
- * done writing.
- */
- final String tempFileName;
-
- FolderCacheStorage(this.folder, this.tempFileName);
-
- @override
- List<int> get(String key) {
- Resource file = folder.getChild(key);
- if (file is File) {
- try {
- return file.readAsBytesSync();
- } on FileSystemException {}
- }
- return null;
- }
-
- @override
- void put(String key, List<int> bytes) {
- String absPath = folder.getChild(key).path;
- File tempFile = folder.getChild(tempFileName);
- tempFile.writeAsBytesSync(bytes);
- try {
- tempFile.renameSync(absPath);
- } catch (e) {}
- }
-}
-
-/**
* Cache of information to support incremental analysis.
*
* Note that currently this class is not intended for interactive use.
@@ -101,6 +60,7 @@ class IncrementalCache {
final Map<Source, CacheSourceContent> _sourceContentMap =
<Source, CacheSourceContent>{};
final Map<Source, List<Source>> _libraryClosureMap = <Source, List<Source>>{};
+ final Map<Source, List<int>> _libraryClosureHashMap = <Source, List<int>>{};
final Map<Source, List<int>> _sourceContentHashMap = <Source, List<int>>{};
/**
@@ -108,6 +68,8 @@ class IncrementalCache {
*/
final Map<String, PackageBundle> _bundleMap = <String, PackageBundle>{};
+ final Map<String, Source> _absoluteUriMap = <String, Source>{};
+
IncrementalCache(this.storage, this.context, this.configSalt);
/**
@@ -138,6 +100,9 @@ class IncrementalCache {
if (source.isInSystemLibrary) {
continue;
}
+ if (getSourceKind(source) == SourceKind.PART) {
+ continue;
+ }
String key = _getLibraryBundleKey(source);
PackageBundle bundle = _getLibraryBundle(key);
if (bundle == null) {
@@ -194,8 +159,7 @@ class IncrementalCache {
}
// Append parts.
for (String partUri in contentSource.partUris) {
- Source partSource =
- context.sourceFactory.resolveUri(librarySource, partUri);
+ Source partSource = _resolveUri(librarySource, partUri);
if (partSource == null) {
throw new StateError('Unable to resolve $partUri in $librarySource');
}
@@ -203,8 +167,7 @@ class IncrementalCache {
}
// Append imports and exports.
void appendLibrarySources(String refUri) {
- Source refSource =
- context.sourceFactory.resolveUri(librarySource, refUri);
+ Source refSource = _resolveUri(librarySource, refUri);
if (refSource == null) {
throw new StateError('Unable to resolve $refUri in $librarySource');
}
@@ -285,14 +248,16 @@ class IncrementalCache {
* the given [librarySource].
*/
List<int> _getLibraryClosureHash(Source librarySource) {
- List<Source> closure = _getLibraryClosure(librarySource);
- MD5 md5 = new MD5();
- for (Source source in closure) {
- List<int> sourceHash = _getSourceContentHash(source);
- md5.add(sourceHash);
- }
- md5.add(configSalt);
- return md5.close();
+ return _libraryClosureHashMap.putIfAbsent(librarySource, () {
+ List<Source> closure = _getLibraryClosure(librarySource);
+ MD5 md5 = new MD5();
+ for (Source source in closure) {
+ List<int> sourceHash = _getSourceContentHash(source);
+ md5.add(sourceHash);
+ }
+ md5.add(configSalt);
+ return md5.close();
+ });
}
/**
@@ -307,6 +272,25 @@ class IncrementalCache {
}
/**
+ * Return a source representing the URI that results from resolving the given
+ * (possibly relative) [containedUri] against the URI associated with the
+ * [containingSource], whether or not the resulting source exists, or `null`
+ * if either the [containedUri] is invalid or if it cannot be resolved against
+ * the [containingSource]'s URI.
+ */
+ Source _resolveUri(Source containingSource, String containedUri) {
+ // Cache absolute URIs.
+ if (containedUri.startsWith('dart:') ||
Paul Berry 2016/03/21 20:29:32 If the goal is to figure out whether this is an ab
scheglov 2016/03/21 20:58:26 See the performance results in mail. URI operation
+ containedUri.startsWith('package:')) {
+ return _absoluteUriMap.putIfAbsent(containedUri, () {
+ return context.sourceFactory.resolveUri(containingSource, containedUri);
+ });
+ }
+ // Resolve relative URIs without caching.
+ return context.sourceFactory.resolveUri(containingSource, containedUri);
+ }
+
+ /**
* Write the content based information about the given [source].
*/
void _writeCacheSourceContent(Source source, CacheSourceContentBuilder b) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698