| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bae41fa commit 0c74932
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -236,9 +236,18 @@ public void run() { | |||
| 236 | 236 | // todo: at some point buffer should stop increasing in size, | |
| 237 | 237 | // otherwise it could use up all the memory. | |
| 238 | 238 | if (bufferLast == buffer.length) { | |
| 239 | - byte temp[] = new byte[bufferLast << 1]; | ||
| 240 | - System.arraycopy(buffer, 0, temp, 0, bufferLast); | ||
| 241 | - buffer = temp; | ||
| 239 | + if (bufferIndex > 0) { | ||
| 240 | + // compact the buffer | ||
| 241 | + int bufferLength = bufferLast - bufferIndex; | ||
| 242 | + System.arraycopy(buffer, bufferIndex, buffer, 0, bufferLength); | ||
| 243 | + bufferLast -= bufferIndex; | ||
| 244 | + bufferIndex = 0; | ||
| 245 | + } else { | ||
| 246 | + // resize the buffer | ||
| 247 | + byte temp[] = new byte[bufferLast << 1]; | ||
| 248 | + System.arraycopy(buffer, 0, temp, 0, bufferLast); | ||
| 249 | + buffer = temp; | ||
| 250 | + } | ||
| 242 | 251 | } | |
| 243 | 252 | buffer[bufferLast++] = (byte)value; | |
| 244 | 253 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments