Skip to content

Commit 7860f67

Browse files
author
Ruben Bridgewater
committed
Decrease the buffer offset if the buffer pool is shrunk
1 parent 2a89bee commit 7860f67

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/parser.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,14 @@ function decreaseBufferPool () {
317317
if (bufferPool.length > 50 * 1024) {
318318
// Balance between increasing and decreasing the bufferPool
319319
if (counter === 1 || notDecreased > counter * 2) {
320-
// Decrease the bufferPool by 16kb by removing the first 16kb of the current pool
321-
bufferPool = bufferPool.slice(Math.floor(bufferPool.length / 10), bufferPool.length)
320+
// Decrease the bufferPool by 10% by removing the first 10% of the current pool
321+
var sliceLength = Math.floor(bufferPool.length / 10)
322+
if (bufferOffset <= sliceLength) {
323+
bufferOffset = 0
324+
} else {
325+
bufferOffset -= sliceLength
326+
}
327+
bufferPool = bufferPool.slice(sliceLength, bufferPool.length)
322328
} else {
323329
notDecreased++
324330
counter--

0 commit comments

Comments
 (0)