@@ -35,7 +35,18 @@ export type DecodeOptions<ContextType = undefined> = Readonly<
3535> &
3636 ContextOf < ContextType > ;
3737
38+ const getDecoder = ( options : any ) => new Decoder (
39+ options . extensionCodec ,
40+ ( options as typeof options & { context : any } ) . context ,
41+ options . maxStrLength ,
42+ options . maxBinLength ,
43+ options . maxArrayLength ,
44+ options . maxMapLength ,
45+ options . maxExtLength ,
46+ ) ;
47+
3848export const defaultDecodeOptions : DecodeOptions = { } ;
49+ const defaultDecoder = getDecoder ( defaultDecodeOptions ) ;
3950
4051/**
4152 * It decodes a single MessagePack object in a buffer.
@@ -47,15 +58,7 @@ export function decode<ContextType = undefined>(
4758 buffer : ArrayLike < number > | BufferSource ,
4859 options : DecodeOptions < SplitUndefined < ContextType > > = defaultDecodeOptions as any ,
4960) : unknown {
50- const decoder = new Decoder (
51- options . extensionCodec ,
52- ( options as typeof options & { context : any } ) . context ,
53- options . maxStrLength ,
54- options . maxBinLength ,
55- options . maxArrayLength ,
56- options . maxMapLength ,
57- options . maxExtLength ,
58- ) ;
61+ const decoder = options === defaultDecodeOptions ? defaultDecoder : getDecoder ( options ) ;
5962 return decoder . decode ( buffer ) ;
6063}
6164
@@ -67,14 +70,6 @@ export function decodeMulti<ContextType = undefined>(
6770 buffer : ArrayLike < number > | BufferSource ,
6871 options : DecodeOptions < SplitUndefined < ContextType > > = defaultDecodeOptions as any ,
6972) : Generator < unknown , void , unknown > {
70- const decoder = new Decoder (
71- options . extensionCodec ,
72- ( options as typeof options & { context : any } ) . context ,
73- options . maxStrLength ,
74- options . maxBinLength ,
75- options . maxArrayLength ,
76- options . maxMapLength ,
77- options . maxExtLength ,
78- ) ;
73+ const decoder = options === defaultDecodeOptions ? defaultDecoder : getDecoder ( options ) ;
7974 return decoder . decodeMulti ( buffer ) ;
8075}
0 commit comments