Chromium Code Reviews| Index: pkg/compiler/lib/src/deferred_load.dart |
| diff --git a/pkg/compiler/lib/src/deferred_load.dart b/pkg/compiler/lib/src/deferred_load.dart |
| index 114bdcaaf8886442f87a8fc3b0fd7dbe63de1948..6485a8203d4af428b52bc00d5d1a25fd1ccd17dc 100644 |
| --- a/pkg/compiler/lib/src/deferred_load.dart |
| +++ b/pkg/compiler/lib/src/deferred_load.dart |
| @@ -222,11 +222,24 @@ class DeferredLoadTask extends CompilerTask { |
| return outputUnitTo.imports.containsAll(outputUnitFrom.imports); |
| } |
| + // TODO(het): use a union-find to canonicalize output units |
| + OutputUnit _getCanonicalUnit(OutputUnit outputUnit) { |
| + OutputUnit representative = allOutputUnits.lookup(outputUnit); |
| + if (representative == null) { |
| + representative = outputUnit; |
| + allOutputUnits.add(representative); |
| + } |
| + return representative; |
| + } |
| + |
| void registerConstantDeferredUse( |
| DeferredConstantValue constant, PrefixElement prefix) { |
| OutputUnit outputUnit = new OutputUnit(); |
| outputUnit.imports.add(new _DeclaredDeferredImport(prefix.deferredImport)); |
| - _constantToOutputUnit[constant] = outputUnit; |
| + |
| + // Check to see if there is already a canonical output unit registered. |
| + OutputUnit representative = _getCanonicalUnit(outputUnit); |
| + _constantToOutputUnit[constant] = representative; |
| } |
| /// Answers whether [element] is explicitly deferred when referred to from |
| @@ -679,6 +692,11 @@ class DeferredLoadTask extends CompilerTask { |
| Map<ConstantValue, OutputUnit> constantToOutputUnitBuilder = |
| new Map<ConstantValue, OutputUnit>(); |
| + // Add all constants that may have been registered during |
| + // resolution with [registerConstantDeferredUse]. |
| + constantToOutputUnitBuilder.addAll(_constantToOutputUnit); |
| + _constantToOutputUnit.clear(); |
| + |
| // Reverse the mappings. For each element record an OutputUnit |
| // collecting all deferred imports mapped to this element. Same |
| // for constants. |
| @@ -721,20 +739,12 @@ class DeferredLoadTask extends CompilerTask { |
| // to, and canonicalize them. |
| elementToOutputUnitBuilder |
| .forEach((Element element, OutputUnit outputUnit) { |
| - OutputUnit representative = allOutputUnits.lookup(outputUnit); |
| - if (representative == null) { |
| - representative = outputUnit; |
| - allOutputUnits.add(representative); |
| - } |
| + OutputUnit representative = _getCanonicalUnit(outputUnit); |
|
Siggi Cherem (dart-lang)
2016/09/07 23:57:50
now that the logic is pulled out, consider removin
Harry Terkelsen
2016/09/08 00:01:29
Done.
|
| _elementToOutputUnit[element] = representative; |
| }); |
| constantToOutputUnitBuilder |
| .forEach((ConstantValue constant, OutputUnit outputUnit) { |
| - OutputUnit representative = allOutputUnits.lookup(outputUnit); |
| - if (representative == null) { |
| - representative = outputUnit; |
| - allOutputUnits.add(representative); |
| - } |
| + OutputUnit representative = _getCanonicalUnit(outputUnit); |
| _constantToOutputUnit[constant] = representative; |
| }); |