make local variables first when accessing fields multiple times

This commit is contained in:
2020-11-07 13:13:38 +01:00
parent 88f7abfc91
commit 50d2901b72

View File

@@ -114,13 +114,13 @@ class MultiwayLongMerger {
private static final LongQueue[] EMPTY_QUEUE = new LongQueue[0];
private LongQueue[] longQueues;
private LongQueue[] mLongQueues;
/*
* a classic heap where the nodes are layed out in breath first order. First the
* root, then the nodes of level 1, then the nodes of level 2, ...
*/
private final long[] heap;
private final long[] mHeap;
private final int size;
@@ -129,11 +129,11 @@ class MultiwayLongMerger {
public MinValuePriorityQueue(final Collection<LongQueue> longQueues) {
final List<LongQueue> tmpQueues = new ArrayList<>(longQueues);
size = longQueues.size();
heap = new long[2 * nextPowOfTwo(size) - 1];
mHeap = new long[2 * nextPowOfTwo(size) - 1];
firstLeafIndex = heap.length / 2;
firstLeafIndex = mHeap.length / 2;
Arrays.fill(heap, UNSET);
Arrays.fill(mHeap, UNSET);
// fill the longQueues list with empty queues, so that we
// have a queue for every leaf in the heap. This makes fillWithMinOfChildren()
@@ -141,7 +141,7 @@ class MultiwayLongMerger {
for (int i = size; i < nextPowOfTwo(size); i++) {
tmpQueues.add(LongQueue.EMPTY);
}
this.longQueues = tmpQueues.toArray(EMPTY_QUEUE);
this.mLongQueues = tmpQueues.toArray(EMPTY_QUEUE);
init();
}
@@ -156,7 +156,7 @@ class MultiwayLongMerger {
* heap is empty
*/
public long pop() {
long result = heap[0];
long result = mHeap[0];
if (result != UNSET) {
fillWithMinOfChildren(0);
}
@@ -186,8 +186,8 @@ class MultiwayLongMerger {
// fill leaf nodes
int offset = firstLeafIndex;
for (int j = 0; j < size; j++) {
final LongQueue q = longQueues[j];
heap[offset + j] = q.isEmpty() ? UNSET : q.pop();
final LongQueue q = mLongQueues[j];
mHeap[offset + j] = q.isEmpty() ? UNSET : q.pop();
}
// fill the non-leaf layers (from the leafs up to the root)
@@ -218,7 +218,9 @@ class MultiwayLongMerger {
private void fillWithMinOfChildren(int index) {
int firstLeafOffset = firstLeafIndex;
final int firstLeafOffset = firstLeafIndex;
final long[] heap = mHeap;
final LongQueue[] longQueues = mLongQueues;
int currentIndex = index;
while (true) {
@@ -243,7 +245,7 @@ class MultiwayLongMerger {
}
if (currentIndex >= firstLeafOffset) {
final int listIndex = currentIndex - firstLeafIndex; // leafIndexToListIndex(index);
final int listIndex = currentIndex - firstLeafOffset; // leafIndexToListIndex(index);
final LongQueue queue = longQueues[listIndex];
heap[currentIndex] = queue.isEmpty() ? UNSET : queue.pop();
return;