Skip to content

Commit

Permalink
immutable: Remove a variable store in a loop
Browse files Browse the repository at this point in the history
This also makes reading the loop more clear that it is incrementing the
index by 2 each iteration.

Signed-off-by: BJ Hargrave <bj@hargrave.dev>
  • Loading branch information
bjhargrave committed May 6, 2022
1 parent 815cb77 commit 81fb609
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ private static short[] hash(Object[] entries) {
throw new IllegalArgumentException("map too large: " + length);
}
short[] hash_bucket = new short[length * 2];
for (int slot = 0, index = 0; slot < length;) {
Object key = entries[index++];
for (int slot = 0, index = 0; slot < length; index += 2) {
Object key = entries[index];
int hash = -1 - linear_probe(entries, hash_bucket, key);
if (hash < 0) {
throw new IllegalArgumentException("duplicate key: " + key);
}
hash_bucket[hash] = (short) ++slot;
requireNonNull(entries[index++]);
requireNonNull(entries[index + 1]);
}
return hash_bucket;
}
Expand Down

0 comments on commit 81fb609

Please sign in to comment.