Skip to content

Commit

Permalink
Polishing #2042
Browse files Browse the repository at this point in the history
Initialize collections with sizes.

Original pull request: #2044.
  • Loading branch information
mp911de committed Mar 16, 2022
1 parent b65443f commit 0838a6b
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,17 +291,17 @@ public RedisFuture<List<KeyValue<K, V>>> mget(Iterable<K> keys) {
}

// For a given partition, maps the key to its index within the List<K> in partitioned for faster lookups below
Map<Integer, Map<K,Integer>> partitionedKeysToIndexes = new HashMap<>();
Map<Integer, Map<K, Integer>> partitionedKeysToIndexes = new HashMap<>(partitioned.size());
for (Integer partition : partitioned.keySet()) {
List<K> keysForPartition = partitioned.get(partition);
Map<K, Integer> keysToIndexes = new HashMap<>();
Map<K, Integer> keysToIndexes = new HashMap<>(keysForPartition.size());
for (int i = 0; i < keysForPartition.size(); i++) {
keysToIndexes.put(keysForPartition.get(i), i);
}
partitionedKeysToIndexes.put(partition, keysToIndexes);
}
Map<K, Integer> slots = SlotHash.getSlots(partitioned);
Map<Integer, RedisFuture<List<KeyValue<K, V>>>> executions = new HashMap<>();
Map<Integer, RedisFuture<List<KeyValue<K, V>>>> executions = new HashMap<>(partitioned.size());

for (Map.Entry<Integer, List<K>> entry : partitioned.entrySet()) {
RedisFuture<List<KeyValue<K, V>>> mget = super.mget(entry.getValue());
Expand All @@ -310,7 +310,7 @@ public RedisFuture<List<KeyValue<K, V>>> mget(Iterable<K> keys) {

// restore order of key
return new PipelinedRedisFuture<>(executions, objectPipelinedRedisFuture -> {
List<KeyValue<K, V>> result = new ArrayList<>();
List<KeyValue<K, V>> result = new ArrayList<>(slots.size());
for (K opKey : keys) {
int slot = slots.get(opKey);

Expand Down

0 comments on commit 0838a6b

Please sign in to comment.