From 85175f080654464b3acd45c0db368e2243d33168 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Tue, 30 Nov 2021 15:26:51 +0700 Subject: [PATCH 1/3] Do not call varint.decode() if 0 length --- src/coder/decode.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/coder/decode.js b/src/coder/decode.js index 60e0425..c82395b 100644 --- a/src/coder/decode.js +++ b/src/coder/decode.js @@ -33,6 +33,10 @@ class Decoder { const msgs = [] while (true) { + if (!this._buffer.length) { + // after consuming the whole length, _buffer has 0 length so don't want to bother varint + break; + } if (!this._headerInfo) { try { this._headerInfo = this._decodeHeader(this._bufferProxy) From 147e1359c5d3ebc442ba47f7b6f999792a675de6 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Wed, 1 Dec 2021 09:10:01 +0700 Subject: [PATCH 2/3] Remove semicolon --- src/coder/decode.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coder/decode.js b/src/coder/decode.js index c82395b..7623bba 100644 --- a/src/coder/decode.js +++ b/src/coder/decode.js @@ -35,7 +35,7 @@ class Decoder { while (true) { if (!this._buffer.length) { // after consuming the whole length, _buffer has 0 length so don't want to bother varint - break; + break } if (!this._headerInfo) { try { From 244c3e78b2c71bfffe5a222e202867b7f894895a Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Tue, 7 Dec 2021 05:50:40 +0700 Subject: [PATCH 3/3] No introduce new branch --- src/coder/decode.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/coder/decode.js b/src/coder/decode.js index 7623bba..94f93be 100644 --- a/src/coder/decode.js +++ b/src/coder/decode.js @@ -32,11 +32,7 @@ class Decoder { this._buffer.append(chunk) const msgs = [] - while (true) { - if (!this._buffer.length) { - // after consuming the whole length, _buffer has 0 length so don't want to bother varint - break - } + while (this._buffer.length) { if (!this._headerInfo) { try { this._headerInfo = this._decodeHeader(this._bufferProxy)