Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.

Commit be43102

Browse files
committed
switch loop with stream
1 parent 04b7cae commit be43102

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/KeyRangeCache.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.TreeMap;
3838
import java.util.concurrent.ThreadLocalRandom;
3939
import java.util.concurrent.atomic.AtomicLong;
40+
import java.util.stream.IntStream;
4041

4142
/** Cache for routing information used by location-aware routing. */
4243
@InternalApi
@@ -272,10 +273,7 @@ private int uniformRandom(int n, ByteString seed1, ByteString seed2, ByteString
272273
}
273274

274275
private int[] sampleWithoutReplacement(int populationSize, int sampleSize) {
275-
int[] indexes = new int[populationSize];
276-
for (int i = 0; i < populationSize; i++) {
277-
indexes[i] = i;
278-
}
276+
int[] indexes = IntStream.range(0, populationSize).toArray();
279277
for (int i = 0; i < sampleSize; i++) {
280278
int j = i + ThreadLocalRandom.current().nextInt(populationSize - i);
281279
int tmp = indexes[i];

0 commit comments

Comments
 (0)