From d4ebde1b7349abd3bffa26b408b1b49961608fa4 Mon Sep 17 00:00:00 2001 From: Sergey Zenchenko Date: Fri, 30 Aug 2019 13:35:05 +0300 Subject: [PATCH] Add flag for cachedKeyDecoder usage (#85) * Add flag for cachedKeyDecoder usage * Update api --- src/Decoder.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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);