@@ -137,7 +137,6 @@ function parseBulkString (parser) {
137
137
parser . bigStrSize = offsetEnd + 2
138
138
parser . bigOffset = parser . offset
139
139
parser . totalChunkSize = parser . buffer . length
140
- parser . bufferCache . push ( parser . buffer )
141
140
return
142
141
}
143
142
@@ -348,20 +347,20 @@ JavascriptRedisParser.prototype.execute = function (buffer) {
348
347
this . offset = 0
349
348
} else if ( this . bigStrSize === 0 ) {
350
349
var oldLength = this . buffer . length
351
- var remainingLength = oldLength - this . offset
352
- var newLength = remainingLength + buffer . length
350
+ var newLength = oldLength + buffer . length
353
351
// ~ 5% speed increase over using new Buffer(length) all the time
354
352
if ( bufferPool . length < newLength ) { // We can't rely on the chunk size
355
353
bufferPool = new Buffer ( newLength )
356
354
}
357
- this . buffer . copy ( bufferPool , 0 , this . offset , oldLength )
358
- buffer . copy ( bufferPool , remainingLength , 0 , buffer . length )
355
+ this . buffer . copy ( bufferPool , 0 , 0 , oldLength )
356
+ buffer . copy ( bufferPool , oldLength , 0 , buffer . length )
359
357
this . buffer = bufferPool . slice ( 0 , newLength )
360
358
this . offset = 0
361
359
} else if ( this . totalChunkSize + buffer . length >= this . bigStrSize ) {
360
+ this . bufferCache . unshift ( this . buffer )
362
361
this . bufferCache . push ( buffer )
363
362
// The returned type might be Array * (42) and in that case we can't improve the parsing currently
364
- if ( this . optionReturnBuffers === false && this . buffer [ this . offset ] === 36 ) {
363
+ if ( this . optionReturnBuffers === false && this . buffer [ 0 ] === 36 ) {
365
364
this . returnReply ( concatBulkString ( this ) )
366
365
this . buffer = buffer
367
366
} else { // This applies for arrays too
@@ -382,7 +381,18 @@ JavascriptRedisParser.prototype.execute = function (buffer) {
382
381
var type = this . buffer [ this . offset ++ ]
383
382
var response = parseType ( this , type )
384
383
if ( response === undefined ) {
385
- this . offset = offset
384
+ if ( this . buffer === null ) {
385
+ return
386
+ }
387
+ var tempBuffer = new Buffer ( this . buffer . length - offset )
388
+ this . buffer . copy ( tempBuffer , 0 , offset , this . buffer . length )
389
+ this . buffer = tempBuffer
390
+ if ( this . bigStrSize !== 0 ) {
391
+ this . bigStrSize -= offset
392
+ this . bigOffset -= offset
393
+ this . totalChunkSize -= offset
394
+ }
395
+ this . offset = 0
386
396
return
387
397
}
388
398
0 commit comments