}
private void computeFragmentMap(JProgram jprogram, JsProgram jsProgram) {
int fragments = jsProgram.getFragmentCount();
List<Integer> initSeq = jprogram.getInitialFragmentIdSequence();
FragmentPartitioningResult partitionResult = jprogram.getFragmentPartitioningResult();
//
// The fragments are expected in a specific order:
// init, split-1, split-2, ...,
// where the leftovers are dependent on the init module
// and the split modules are dependent on the leftovers
//
// However, Closure Compiler modules must be in dependency order
//
assert closureModuleSequenceMap == null;
closureModuleSequenceMap = new int[fragments];
for (int i = 0; i < fragments; i++) {
closureModuleSequenceMap[i] = -1;
}
int module = 0;
// The initial fragments is always first.
closureModuleSequenceMap[0] = module++;
// Then come the specified load order sequence
for (int i = 0; i < initSeq.size(); i++) {
int initSeqNum = initSeq.get(i);
if (partitionResult != null) {
initSeqNum = partitionResult.getFragmentForRunAsync(initSeqNum);
}
closureModuleSequenceMap[initSeqNum] = module++;
}
// Then the leftovers fragments:
if (fragments > 1) {
int leftoverIndex = fragments - 1;
if (partitionResult != null) {
leftoverIndex = partitionResult.getLeftoverFragmentId();
}
closureModuleSequenceMap[leftoverIndex] = module++;
}
// Finally, the exclusive fragments.