Index: sdk/lib/_internal/compiler/implementation/library_loader.dart |
diff --git a/sdk/lib/_internal/compiler/implementation/library_loader.dart b/sdk/lib/_internal/compiler/implementation/library_loader.dart |
index dfb3258e055c11ccafa8a6642882fce642a84e14..71ebc2deebd6751d642ec270ca6ca39513914f89 100644 |
--- a/sdk/lib/_internal/compiler/implementation/library_loader.dart |
+++ b/sdk/lib/_internal/compiler/implementation/library_loader.dart |
@@ -123,24 +123,26 @@ import 'util/util.dart' show Link, LinkBuilder; |
abstract class LibraryLoaderTask implements CompilerTask { |
factory LibraryLoaderTask(Compiler compiler) = _LibraryLoaderTask; |
- /** |
- * Loads the library specified by the [resolvedUri] and returns its |
- * [LibraryElement]. |
- * |
- * If the library is not already loaded, the method creates the |
- * [LibraryElement] for the library and computes the import/export scope, |
- * loading and computing the import/export scopes of all required libraries in |
- * the process. The method handles cyclic dependency between libraries. |
- */ |
+ /// Returns all libraries that have been loaded. |
+ Iterable<LibraryElement> get libraries; |
+ |
+ /// Looks up the library with the [canonicalUri]. |
+ LibraryElement lookupLibrary(Uri canonicalUri); |
+ |
+ /// Loads the library specified by the [resolvedUri] and returns its |
+ /// [LibraryElement]. |
+ /// |
+ /// If the library is not already loaded, the method creates the |
+ /// [LibraryElement] for the library and computes the import/export scope, |
+ /// loading and computing the import/export scopes of all required libraries |
+ /// in the process. The method handles cyclic dependency between libraries. |
Future<LibraryElement> loadLibrary(Uri resolvedUri); |
- /// Reset the library loader task to prepare for compilation. This is used |
- /// for incremental compilation. |
- void reset(); |
- |
- /// Reuse [library] from a previous compilation. This is used for incremental |
- /// compilation. |
- void reuseLibrary(LibraryElement library); |
+ /// Reset the library loader task to prepare for compilation. If provided, |
+ /// libraries matching [reuseLibrary] are reused. |
+ /// |
+ /// This method is used for incremental compilation. |
+ void reset({bool reuseLibrary(LibraryElement library)}); |
} |
/// Handle for creating synthesized/patch libraries during library loading. |
@@ -246,6 +248,8 @@ class _LibraryLoaderTask extends CompilerTask implements LibraryLoaderTask { |
_LibraryLoaderTask(Compiler compiler) : super(compiler); |
String get name => 'LibraryLoader'; |
+ final Map<Uri, LibraryElement> libraryCanonicalUriMap = |
+ new Map<Uri, LibraryElement>(); |
final Map<Uri, LibraryElement> libraryResourceUriMap = |
new Map<Uri, LibraryElement>(); |
final Map<String, LibraryElement> libraryNames = |
@@ -253,16 +257,34 @@ class _LibraryLoaderTask extends CompilerTask implements LibraryLoaderTask { |
LibraryDependencyHandler currentHandler; |
- void reset() { |
+ Iterable<LibraryElement> get libraries => libraryCanonicalUriMap.values; |
+ |
+ LibraryElement lookupLibrary(Uri canonicalUri) { |
+ return libraryCanonicalUriMap[canonicalUri]; |
+ } |
+ |
+ void reset({bool reuseLibrary(LibraryElement library)}) { |
assert(currentHandler == null); |
+ Iterable<LibraryElement> libraries = |
+ new List.from(libraryCanonicalUriMap.values); |
+ |
+ libraryCanonicalUriMap.clear(); |
libraryResourceUriMap.clear(); |
libraryNames.clear(); |
+ |
+ if (reuseLibrary == null) return; |
+ |
+ libraries.where(reuseLibrary).forEach(mapLibrary); |
} |
- void reuseLibrary(LibraryElement library) { |
- String name = library.getLibraryOrScriptName(); |
+ /// Insert [library] in the internal maps. Used for compiler reuse. |
+ void mapLibrary(LibraryElement library) { |
+ libraryCanonicalUriMap[library.canonicalUri] = library; |
+ |
Uri resourceUri = library.entryCompilationUnit.script.resourceUri; |
libraryResourceUriMap[resourceUri] = library; |
+ |
+ String name = library.getLibraryOrScriptName(); |
libraryNames[name] = library; |
} |
@@ -488,7 +510,7 @@ class _LibraryLoaderTask extends CompilerTask implements LibraryLoaderTask { |
Uri readableUri = |
compiler.translateResolvedUri(importingLibrary, resolvedUri, node); |
if (readableUri == null) return new Future.value(); |
- LibraryElement library = compiler.libraries[resolvedUri.toString()]; |
+ LibraryElement library = libraryCanonicalUriMap[resolvedUri]; |
if (library != null) { |
return new Future.value(library); |
} |
@@ -500,7 +522,7 @@ class _LibraryLoaderTask extends CompilerTask implements LibraryLoaderTask { |
compiler.withCurrentElement(element, () { |
handler.registerNewLibrary(element); |
native.maybeEnableNative(compiler, element); |
- compiler.libraries[resolvedUri.toString()] = element; |
+ libraryCanonicalUriMap[resolvedUri] = element; |
compiler.scanner.scanLibrary(element); |
}); |
return processLibraryTags(handler, element).then((_) { |