inline of array in LongQueue by creating a getting a reference to the

array of LongList
This commit is contained in:
2020-11-07 08:45:51 +01:00
parent c9dcbdbe97
commit 88f7abfc91
2 changed files with 16 additions and 9 deletions

View File

@@ -669,6 +669,10 @@ public final class LongList implements Serializable, Cloneable {
System.arraycopy(data, 0, input, 0, size); System.arraycopy(data, 0, input, 0, size);
return input; return input;
} }
long[] getArrayInternal() {
return data;
}
/** /**
* Sorts the list into ascending order. * Sorts the list into ascending order.

View File

@@ -11,40 +11,43 @@ class MultiwayLongMerger {
static class LongQueue { static class LongQueue {
private static final LongQueue EMPTY = new LongQueue(LongList.of()); private static final LongQueue EMPTY = new LongQueue(LongList.of());
final LongList wrapped; final long[] wrapped;
int offset = 0; int offset = 0;
private int size;
public LongQueue(LongList wrapped) { public LongQueue(LongList wrapped) {
this.wrapped = wrapped; this.wrapped = wrapped.getArrayInternal();
this.size = wrapped.size();
} }
boolean isEmpty() { boolean isEmpty() {
return offset >= wrapped.size(); return offset >= size;
} }
long pop() { long pop() {
assert offset < wrapped.size(); assert offset < size;
final long result = wrapped.get(offset); final long result = wrapped[offset];
offset++; offset++;
return result; return result;
} }
public long peek() { public long peek() {
return wrapped.get(offset); return wrapped[offset];
} }
public long peekLast() { public long peekLast() {
return wrapped.get(wrapped.size() - 1); return wrapped[size - 1];
} }
@Override @Override
public String toString() { public String toString() {
return wrapped.sublist(offset).toString(); return Arrays.toString(Arrays.copyOfRange(wrapped, offset, size));
} }
public int size() { public int size() {
return wrapped.size() - offset; return size - offset;
} }
} }