Skip to content

Commit

Permalink
Add flag for cachedKeyDecoder usage (#85)
Browse files Browse the repository at this point in the history
* Add flag for cachedKeyDecoder usage

* Update api
  • Loading branch information
sergeyzenchenko authored Aug 30, 2019
1 parent 695f3b4 commit d4ebde1
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/Decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,14 @@ export class Decoder {
headByte = HEAD_BYTE_REQUIRED;
readonly stack: Array<StackState> = [];

// TODO: parameterize this property.
readonly cachedKeyDecoder = sharedCachedKeyDecoder;

constructor(
readonly extensionCodec = ExtensionCodec.defaultCodec,
readonly maxStrLength = DEFAULT_MAX_LENGTH,
readonly maxBinLength = DEFAULT_MAX_LENGTH,
readonly maxArrayLength = DEFAULT_MAX_LENGTH,
readonly maxMapLength = DEFAULT_MAX_LENGTH,
readonly maxExtLength = DEFAULT_MAX_LENGTH,
readonly cachedKeyDecoder: CachedKeyDecoder | null = sharedCachedKeyDecoder,
) {}

setBuffer(buffer: ArrayLike<number> | ArrayBuffer): void {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d4ebde1

Please sign in to comment.