@@ -72,13 +72,6 @@ class ModuleMetadata {
7272 ModuleMetadata ._(this .moduleImportName, this .moduleName,
7373 {this .skipEmit = false , this .isMain = false });
7474
75- /// Whether or not the provided kernel [Reference] is included in this module.
76- bool containsReference (Reference reference) {
77- final enclosingLibrary = _enclosingLibraryForReference (reference);
78- if (enclosingLibrary == null ) return false ;
79- return libraries.contains (enclosingLibrary);
80- }
81-
8275 @override
8376 String toString () => '$moduleImportName ($libraries )' ;
8477}
@@ -88,6 +81,12 @@ class ModuleOutputData {
8881 /// All [ModuleMetadata] s generated for the program.
8982 final List <ModuleMetadata > modules;
9083
84+ /// Maps the [Library] to the corresponding [ModuleMetadata] .
85+ late final Map <Library , ModuleMetadata > _libraryToModuleMetadata = {
86+ for (final metadata in modules)
87+ for (final library in metadata.libraries) library: metadata,
88+ };
89+
9190 ModuleOutputData (this .modules) : assert (modules[0 ].isMain);
9291
9392 ModuleMetadata get mainModule => modules[0 ];
@@ -96,8 +95,9 @@ class ModuleOutputData {
9695 bool get hasMultipleModules => modules.length > 1 ;
9796
9897 /// Returns the module that contains [reference] .
99- ModuleMetadata moduleForReference (Reference reference) =>
100- modules.firstWhere ((e) => e.containsReference (reference));
98+ ModuleMetadata moduleForReference (Reference reference) {
99+ return _libraryToModuleMetadata[_enclosingLibraryForReference (reference)]! ;
100+ }
101101}
102102
103103/// Module strategy that puts all libraries into a single module.
0 commit comments