diff --git a/src/decode.ts b/src/decode.ts index 413b85d0..6eb9bd14 100644 --- a/src/decode.ts +++ b/src/decode.ts @@ -36,6 +36,7 @@ export type DecodeOptions = Readonly< ContextOf; export const defaultDecodeOptions: DecodeOptions = {}; +const defaultDecoder = new Decoder(defaultDecodeOptions as any); /** * It decodes a single MessagePack object in a buffer. @@ -47,7 +48,7 @@ export function decode( buffer: ArrayLike | BufferSource, options: DecodeOptions> = defaultDecodeOptions as any, ): unknown { - const decoder = new Decoder( + const decoder = options === defaultDecodeOptions ? defaultDecoder : new Decoder( options.extensionCodec, (options as typeof options & { context: any }).context, options.maxStrLength, diff --git a/src/encode.ts b/src/encode.ts index 6cb1735a..5b71e459 100644 --- a/src/encode.ts +++ b/src/encode.ts @@ -36,6 +36,7 @@ export type EncodeOptions = Partial< ContextOf; const defaultEncodeOptions: EncodeOptions = {}; +const defaultEncoder = new Encoder(defaultEncodeOptions as any); /** * It encodes `value` in the MessagePack format and @@ -47,7 +48,7 @@ export function encode( value: unknown, options: EncodeOptions> = defaultEncodeOptions as any, ): Uint8Array { - const encoder = new Encoder( + const encoder = options === defaultEncodeOptions ? defaultEncoder : new Encoder( options.extensionCodec, (options as typeof options & { context: any }).context, options.maxDepth,