Skip to content

Commit 55f713a

Browse files
committed
PDFBOX-5965: refactor, avoid creating intermediate buffer
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1925266 13f79535-47bb-0310-9956-ffa450edef68
1 parent d9c1b7a commit 55f713a

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

io/src/main/java/org/apache/pdfbox/io/NonSeekableRandomAccessReadInputStream.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,9 @@ private boolean fetch() throws IOException
195195
if (bufferBytes[LAST] == BUFFER_SIZE && bufferBytes[CURRENT] > 0 && bufferBytes[CURRENT] < BUFFER_SIZE)
196196
{
197197
// Likely EOF, we're risking losing the previous (full) buffer and get an AIOOB
198-
// Create a new LAST buffer that combines as much as possible of CURRENT and LAST into a new LAST.
199-
byte[] newBuffer = new byte[BUFFER_SIZE];
200-
System.arraycopy(buffers[LAST], bufferBytes[CURRENT], newBuffer, 0, BUFFER_SIZE - bufferBytes[CURRENT]);
201-
System.arraycopy(buffers[CURRENT], 0, newBuffer, BUFFER_SIZE - bufferBytes[CURRENT], bufferBytes[CURRENT]);
202-
switchBuffers(CURRENT, LAST);
203-
buffers[LAST] = newBuffer;
198+
// Fill LAST with as much as possible data of LAST and CURRENT
199+
System.arraycopy(buffers[LAST], bufferBytes[CURRENT], buffers[LAST], 0, BUFFER_SIZE - bufferBytes[CURRENT]);
200+
System.arraycopy(buffers[CURRENT], 0, buffers[LAST], BUFFER_SIZE - bufferBytes[CURRENT], bufferBytes[CURRENT]);
204201
bufferBytes[LAST] = BUFFER_SIZE;
205202
}
206203
else

0 commit comments

Comments
 (0)