Skip to content

Commit d7de735

Browse files
brad4dcopybara-github
authored andcommitted
Use LinkedHash(Map|Set) to guarantee deterministic iteration order
instrumentation PiperOrigin-RevId: 624959325
1 parent b035c9a commit d7de735

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/com/google/javascript/jscomp/instrumentation/FileInstrumentationData.java

+17-16
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@
2222
import com.google.common.primitives.UnsignedBytes;
2323
import com.google.javascript.rhino.Node;
2424
import java.util.BitSet;
25-
import java.util.HashMap;
25+
import java.util.LinkedHashMap;
2626
import java.util.Map;
2727

2828
/**
29-
* Holds instrumentation details related to a file, namely, the filename,
30-
* the array name used in instrumentation, and the lines which were
31-
* instrumented (in encoded form).
29+
* Holds instrumentation details related to a file, namely, the filename, the array name used in
30+
* instrumentation, and the lines which were instrumented (in encoded form).
3231
*/
3332
@GwtIncompatible("com.google.common.primitives.UnsignedBytes")
3433
class FileInstrumentationData {
@@ -67,8 +66,7 @@ public int hashCode() {
6766
public boolean equals(Object object) {
6867
if (object instanceof BranchIndexPair) {
6968
BranchIndexPair that = (BranchIndexPair) object;
70-
return this.getLine() == that.getLine()
71-
&& this.getBranch() == that.getBranch();
69+
return this.getLine() == that.getLine() && this.getBranch() == that.getBranch();
7270
}
7371
return false;
7472
}
@@ -94,11 +92,11 @@ public boolean equals(Object object) {
9492
instrumentedBits = new BitSet();
9593

9694
branchPresent = new BitSet();
97-
branchesInLine = new HashMap<>();
98-
branchNodes = new HashMap<>();
95+
branchesInLine = new LinkedHashMap<>();
96+
branchNodes = new LinkedHashMap<>();
9997
}
10098

101-
String getArrayName() {
99+
String getArrayName() {
102100
return arrayName;
103101
}
104102

@@ -116,6 +114,7 @@ int maxBranchPresentLine() {
116114

117115
/**
118116
* Store a node to be instrumented later for branch coverage.
117+
*
119118
* @param lineNumber 1-based line number
120119
* @param branchNumber 1-based branch number
121120
* @param block the node of the conditional block.
@@ -131,6 +130,7 @@ void putBranchNode(int lineNumber, int branchNumber, Node block) {
131130

132131
/**
133132
* Get the block node to be instrumented for branch coverage.
133+
*
134134
* @param lineNumber 1-based line number
135135
* @param branchNumber 1-based branch number
136136
* @return the node of the conditional block.
@@ -145,10 +145,9 @@ Node getBranchNode(int lineNumber, int branchNumber) {
145145
}
146146

147147
/**
148-
* Returns a byte-wise hex string representation of the BitField from
149-
* MSB (Most Significant Byte) to LSB (Least Significant Byte).
150-
* Eg. Single byte: a setting of "0001 1111", returns "1f"
151-
* Eg. Multiple bytes: a setting of "0000 0010 0001 1111", returns "1f02"
148+
* Returns a byte-wise hex string representation of the BitField from MSB (Most Significant Byte)
149+
* to LSB (Least Significant Byte). Eg. Single byte: a setting of "0001 1111", returns "1f" Eg.
150+
* Multiple bytes: a setting of "0000 0010 0001 1111", returns "1f02"
152151
*
153152
* @return string representation of bits set
154153
*/
@@ -181,8 +180,8 @@ String getBranchPresentAsHexString() {
181180
}
182181

183182
/**
184-
* Mark given 1-based line number as instrumented. Zero, Negative numbers
185-
* are not allowed.
183+
* Mark given 1-based line number as instrumented. Zero, Negative numbers are not allowed.
184+
*
186185
* @param lineNumber the line number which was instrumented
187186
*/
188187
void setLineAsInstrumented(int lineNumber) {
@@ -195,6 +194,7 @@ void setLineAsInstrumented(int lineNumber) {
195194

196195
/**
197196
* Mark a given 1-based line number has branch presented.
197+
*
198198
* @param lineNumber the line number which has conditional branches.
199199
*/
200200
void setBranchPresent(int lineNumber) {
@@ -207,6 +207,7 @@ void setBranchPresent(int lineNumber) {
207207

208208
/**
209209
* Add a number of branches to a line.
210+
*
210211
* @param lineNumber the line number that contains the branch statement.
211212
* @param numberOfBranches the number of branches to add to the record.
212213
*/
@@ -222,6 +223,7 @@ void addBranches(int lineNumber, int numberOfBranches) {
222223

223224
/**
224225
* Get the number of branches on a line
226+
*
225227
* @param lineNumber - the 1-based line number
226228
* @return the number of branches on the line.
227229
*/
@@ -233,5 +235,4 @@ int getNumBranches(int lineNumber) {
233235
return numBranches;
234236
}
235237
}
236-
237238
}

src/com/google/javascript/jscomp/instrumentation/ProductionCoverageInstrumentationCallback.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import java.io.IOException;
3434
import java.util.ArrayDeque;
3535
import java.util.Deque;
36-
import java.util.HashMap;
3736
import java.util.LinkedHashMap;
3837
import java.util.Map;
3938
import java.util.Objects;
@@ -286,7 +285,7 @@ private static final class ParameterMapping {
286285
ParameterMapping() {
287286
nextUniqueIdentifier = 0;
288287

289-
paramValueEncodings = new HashMap<>();
288+
paramValueEncodings = new LinkedHashMap<>();
290289

291290
// A LinkedHashMap is used so that when keys are printed, keySet() will obtain them in the
292291
// insertion order which corroborates to the index. This helps to avoid the need of sorting

0 commit comments

Comments
 (0)