Use an ImmutableMap for inputOrder
package com.google.javascript.jscomp;
import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableMap;
import com.google.javascript.jscomp.ReferenceCollectingCallback.Reference;
import com.google.javascript.jscomp.ReferenceCollectingCallback.ReferenceCollection;
import com.google.javascript.jscomp.ReferenceCollectingCallback.ReferenceMap;
@@ -24,7 +25,6 @@ import com.google.javascript.rhino.InputId;
import com.google.javascript.rhino.Node;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -44,22 +44,24 @@ class GlobalVarReferenceMap implements ReferenceMap {
private Map<String, ReferenceCollection> refMap = null;
- private final Map<InputId, Integer> inputOrder;
+ private final ImmutableMap<InputId, Integer> inputOrder;
/**
* @param inputs The ordered list of all inputs for the compiler.
*/
GlobalVarReferenceMap(List<CompilerInput> inputs, List<CompilerInput> externs) {
- inputOrder = new HashMap<>();
+ ImmutableMap.Builder<InputId, Integer> inputOrderBuilder = ImmutableMap.builder();
+
int ind = 0;
for (CompilerInput extern : externs) {
- inputOrder.put(extern.getInputId(), ind);
+ inputOrderBuilder.put(extern.getInputId(), ind);
ind++;
}
for (CompilerInput input : inputs) {
- inputOrder.put(input.getInputId(), ind);
+ inputOrderBuilder.put(input.getInputId(), ind);
ind++;
}
+ inputOrder = inputOrderBuilder.build();
}
@Override
