diff --git a/src/Decoder.ts b/src/Decoder.ts index a689ed84..6a3ecefb 100644 --- a/src/Decoder.ts +++ b/src/Decoder.ts @@ -70,9 +70,6 @@ export class Decoder { headByte = HEAD_BYTE_REQUIRED; readonly stack: Array = []; - // TODO: parameterize this property. - readonly cachedKeyDecoder = sharedCachedKeyDecoder; - constructor( readonly extensionCodec = ExtensionCodec.defaultCodec, readonly maxStrLength = DEFAULT_MAX_LENGTH, @@ -80,6 +77,7 @@ export class Decoder { readonly maxArrayLength = DEFAULT_MAX_LENGTH, readonly maxMapLength = DEFAULT_MAX_LENGTH, readonly maxExtLength = DEFAULT_MAX_LENGTH, + readonly cachedKeyDecoder: CachedKeyDecoder | null = sharedCachedKeyDecoder, ) {} setBuffer(buffer: ArrayLike | ArrayBuffer): void { @@ -479,7 +477,7 @@ export class Decoder { const offset = this.pos + headerOffset; let object: string; - if (this.stateIsMapKey() && this.cachedKeyDecoder.canBeCached(byteLength)) { + if (this.cachedKeyDecoder && this.stateIsMapKey() && this.cachedKeyDecoder.canBeCached(byteLength)) { object = this.cachedKeyDecoder.decode(this.bytes, offset, byteLength); } else if (TEXT_ENCODING_AVAILABLE && byteLength > TEXT_DECODER_THRESHOLD) { object = utf8DecodeTD(this.bytes, offset, byteLength);