Skip to content

Commit 85da63f

Browse files
committed
Cleanup in UnsafeShuffleSorterIterator.
1 parent 0ad34da commit 85da63f

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

core/src/main/java/org/apache/spark/shuffle/unsafe/UnsafeShuffleInMemorySorter.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,35 +78,36 @@ public void insertRecord(long recordPointer, int partitionId) {
7878
sortBufferInsertPosition++;
7979
}
8080

81-
public static abstract class UnsafeShuffleSorterIterator {
81+
/**
82+
* An iterator-like class that's used instead of Java's Iterator in order to facilitate inlining.
83+
*/
84+
public static final class UnsafeShuffleSorterIterator {
8285

86+
private final long[] sortBuffer;
87+
private final int numRecords;
8388
final PackedRecordPointer packedRecordPointer = new PackedRecordPointer();
89+
private int position = 0;
8490

85-
public abstract boolean hasNext();
91+
public UnsafeShuffleSorterIterator(int numRecords, long[] sortBuffer) {
92+
this.numRecords = numRecords;
93+
this.sortBuffer = sortBuffer;
94+
}
8695

87-
public abstract void loadNext();
96+
public boolean hasNext() {
97+
return position < numRecords;
98+
}
8899

100+
public void loadNext() {
101+
packedRecordPointer.set(sortBuffer[position]);
102+
position++;
103+
}
89104
}
90105

91106
/**
92107
* Return an iterator over record pointers in sorted order.
93108
*/
94109
public UnsafeShuffleSorterIterator getSortedIterator() {
95110
sorter.sort(sortBuffer, 0, sortBufferInsertPosition, SORT_COMPARATOR);
96-
return new UnsafeShuffleSorterIterator() {
97-
98-
private int position = 0;
99-
100-
@Override
101-
public boolean hasNext() {
102-
return position < sortBufferInsertPosition;
103-
}
104-
105-
@Override
106-
public void loadNext() {
107-
packedRecordPointer.set(sortBuffer[position]);
108-
position++;
109-
}
110-
};
111+
return new UnsafeShuffleSorterIterator(sortBufferInsertPosition, sortBuffer);
111112
}
112113
}

0 commit comments

Comments
 (0)