Skip to content

Commit 0b85eb3

Browse files
brad4dcopybara-github
authored andcommitted
Use LinkedHash(Map|Set) to guarantee deterministic iteration order
PiperOrigin-RevId: 515144252
1 parent b3be252 commit 0b85eb3

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

src/com/google/javascript/jscomp/FunctionArgumentInjector.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import com.google.javascript.rhino.IR;
2828
import com.google.javascript.rhino.Node;
2929
import com.google.javascript.rhino.Token;
30-
import java.util.HashSet;
30+
import java.util.LinkedHashSet;
3131
import java.util.Map;
3232
import java.util.Set;
3333

@@ -197,7 +197,7 @@ private static String getUniqueAnonymousParameterName(
197197
*/
198198
Set<String> findModifiedParameters(Node fnNode) {
199199
ImmutableSet<String> names = getFunctionParameterSet(fnNode);
200-
Set<String> unsafeNames = new HashSet<>();
200+
Set<String> unsafeNames = new LinkedHashSet<>();
201201
return findModifiedParameters(fnNode.getLastChild(), names, unsafeNames, false);
202202
}
203203

@@ -406,7 +406,7 @@ private ImmutableSet<String> findParametersReferencedAfterSideEffect(
406406
ImmutableSet<String> parameters, Node root) {
407407

408408
// TODO(johnlenz): Consider using scope for this.
409-
Set<String> locals = new HashSet<>(parameters);
409+
Set<String> locals = new LinkedHashSet<>(parameters);
410410
gatherLocalNames(root, locals);
411411

412412
ReferencedAfterSideEffect collector = new ReferencedAfterSideEffect(
@@ -442,7 +442,7 @@ private class ReferencedAfterSideEffect implements Visitor, Predicate<Node> {
442442
private final ImmutableSet<String> parameters;
443443
private final ImmutableSet<String> locals;
444444
private boolean sideEffectSeen = false;
445-
private final Set<String> parametersReferenced = new HashSet<>();
445+
private final Set<String> parametersReferenced = new LinkedHashSet<>();
446446
private int loopsEntered = 0;
447447

448448
ReferencedAfterSideEffect(ImmutableSet<String> parameters, ImmutableSet<String> locals) {

src/com/google/javascript/jscomp/FunctionInjector.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
import com.google.javascript.rhino.jstype.JSType;
3232
import java.util.ArrayList;
3333
import java.util.Collection;
34-
import java.util.HashSet;
3534
import java.util.LinkedHashMap;
35+
import java.util.LinkedHashSet;
3636
import java.util.Set;
3737
import org.jspecify.nullness.Nullable;
3838

@@ -832,7 +832,7 @@ private boolean callMeetsBlockInliningRequirements(
832832
boolean hasArgs = !args.isEmpty();
833833
if (hasArgs) {
834834
// Limit the inlining
835-
Set<String> allNamesToAlias = new HashSet<>(namesToAlias);
835+
Set<String> allNamesToAlias = new LinkedHashSet<>(namesToAlias);
836836
functionArgumentInjector.maybeAddTempsForCallArguments(
837837
compiler, calleeFn, args, allNamesToAlias, compiler.getCodingConvention());
838838
if (!allNamesToAlias.isEmpty()) {
@@ -887,7 +887,7 @@ private CanInlineResult canInlineReferenceDirectly(
887887
boolean hasArgs = !args.isEmpty();
888888
if (hasArgs) {
889889
// Limit the inlining
890-
Set<String> allNamesToAlias = new HashSet<>(namesToAlias);
890+
Set<String> allNamesToAlias = new LinkedHashSet<>(namesToAlias);
891891
functionArgumentInjector.maybeAddTempsForCallArguments(
892892
compiler, fnNode, args, allNamesToAlias, compiler.getCodingConvention());
893893
if (!allNamesToAlias.isEmpty()) {

src/com/google/javascript/jscomp/FunctionToBlockMutator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import com.google.javascript.rhino.Node;
3030
import com.google.javascript.rhino.Token;
3131
import java.util.ArrayList;
32-
import java.util.HashMap;
32+
import java.util.LinkedHashMap;
3333
import java.util.List;
3434
import java.util.Map;
3535
import java.util.Map.Entry;
@@ -325,7 +325,7 @@ private Node aliasAndInlineArguments(
325325

326326
// An arg map that will be updated to contain the
327327
// safe aliases.
328-
Map<String, Node> newArgMap = new HashMap<>(argMap);
328+
Map<String, Node> newArgMap = new LinkedHashMap<>(argMap);
329329

330330
// Declare the alias in the same order as they
331331
// are declared.

src/com/google/javascript/jscomp/RenameLabels.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import java.util.ArrayDeque;
2525
import java.util.ArrayList;
2626
import java.util.Deque;
27-
import java.util.HashMap;
28-
import java.util.HashSet;
27+
import java.util.LinkedHashMap;
28+
import java.util.LinkedHashSet;
2929
import java.util.Map;
3030

3131
/**
@@ -90,8 +90,7 @@ static class DefaultNameSupplier implements Supplier<String> {
9090
private final NameGenerator nameGenerator;
9191

9292
private DefaultNameSupplier() {
93-
this.nameGenerator = new DefaultNameGenerator(
94-
new HashSet<String>(), "", null);
93+
this.nameGenerator = new DefaultNameGenerator(new LinkedHashSet<String>(), "", null);
9594
}
9695

9796
@Override
@@ -287,7 +286,7 @@ private static class LabelInfo {
287286

288287

289288
private static class LabelNamespace {
290-
final Map<String, LabelInfo> renameMap = new HashMap<>();
289+
final Map<String, LabelInfo> renameMap = new LinkedHashMap<>();
291290
}
292291

293292
}

0 commit comments

Comments
 (0)