Skip to content

Commit 7238181

Browse files
add short path for skip
1 parent eaa6b4e commit 7238181

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

core/src/main/java/org/apache/spark/io/ReadAheadInputStream.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,11 @@ public long skip(long n) throws IOException {
317317
if (n <= 0L) {
318318
return 0L;
319319
}
320+
if (n <= activeBuffer.remaining()) {
321+
// Only skipping from active buffer is sufficient
322+
activeBuffer.position(toSkip + activeBuffer.position());
323+
return n;
324+
}
320325
stateChangeLock.lock();
321326
long skipped;
322327
try {
@@ -340,13 +345,9 @@ private long skipInternal(long n) throws IOException {
340345
if (available() >= n) {
341346
// we can skip from the internal buffers
342347
int toSkip = (int) n;
343-
if (toSkip <= activeBuffer.remaining()) {
344-
// Only skipping from active buffer is sufficient
345-
activeBuffer.position(toSkip + activeBuffer.position());
346-
return n;
347-
}
348348
// We need to skip from both active buffer and read ahead buffer
349349
toSkip -= activeBuffer.remaining();
350+
assert(toSkip > 0); // skipping from activeBuffer already handled.
350351
activeBuffer.position(0);
351352
activeBuffer.flip();
352353
readAheadBuffer.position(toSkip + readAheadBuffer.position());

0 commit comments

Comments
 (0)