From b90c25e34d719b8f416b75fdeb6c7ff958463ba2 Mon Sep 17 00:00:00 2001 From: Lajos Meszaros Date: Sun, 29 Sep 2024 21:32:49 +0200 Subject: [PATCH] revert(Implode): change back optimization inside outputBits() --- src/Implode.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Implode.ts b/src/Implode.ts index 7de38df..8fc1252 100644 --- a/src/Implode.ts +++ b/src/Implode.ts @@ -383,12 +383,17 @@ export class Implode { const lastBytes = this.outputBuffer.readByte(this.outputBuffer.size() - 1) this.outputBuffer.setByte(-1, lastBytes | getLowestNBitsOf(bitBuffer << outBits, 8)) - this.outBits = getLowestNBitsOf(this.outBits + nBits, 3) + this.outBits = this.outBits + nBits + if (this.outBits > 8) { + this.outBits = getLowestNBitsOf(this.outBits, 3) bitBuffer = bitBuffer >> (8 - outBits) this.outputBuffer.appendByte(getLowestNBitsOf(bitBuffer, 8)) - } else if (this.outBits === 0) { - this.outputBuffer.appendByte(0) + } else { + this.outBits = getLowestNBitsOf(this.outBits, 3) + if (this.outBits === 0) { + this.outputBuffer.appendByte(0) + } } } }