diff --git a/implementations/javascript/package.json b/implementations/javascript/package.json index 5e4b6c8..38a0fe2 100644 --- a/implementations/javascript/package.json +++ b/implementations/javascript/package.json @@ -1,6 +1,6 @@ { "name": "preserves", - "version": "0.6.3", + "version": "0.6.4", "description": "Experimental data serialization format", "homepage": "https://gitlab.com/preserves/preserves", "license": "Apache-2.0", diff --git a/implementations/javascript/src/decoder.ts b/implementations/javascript/src/decoder.ts index a730c50..59f5303 100644 --- a/implementations/javascript/src/decoder.ts +++ b/implementations/javascript/src/decoder.ts @@ -28,7 +28,11 @@ export class Decoder { } write(data: BytesLike) { - this.packet = Bytes.concat([this.packet.slice(this.index), data])._view; + if (this.index === this.packet.length) { + this.packet = underlying(data); + } else { + this.packet = Bytes.concat([this.packet.slice(this.index), data])._view; + } this.index = 0; } @@ -142,6 +146,10 @@ export class Decoder { try_next(): Value | undefined { const start = this.index; + + if (start >= this.packet.length) return void 0; + // ^ important somewhat-common case optimization - avoid the exception + try { return this.next(); } catch (e) {