Skip to content

Commit 44db5ec

Browse files
committed
encode minor performance optimization
msgpack#172
1 parent c66d264 commit 44db5ec

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/encode.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export type EncodeOptions<ContextType = undefined> = Partial<
3636
ContextOf<ContextType>;
3737

3838
const defaultEncodeOptions: EncodeOptions = {};
39+
const defaultEncoder = new Encoder();
3940

4041
/**
4142
* It encodes `value` in the MessagePack format and
@@ -47,7 +48,7 @@ export function encode<ContextType = undefined>(
4748
value: unknown,
4849
options: EncodeOptions<SplitUndefined<ContextType>> = defaultEncodeOptions as any,
4950
): Uint8Array {
50-
const encoder = new Encoder(
51+
const encoder = !options ? defaultEncoder : new Encoder(
5152
options.extensionCodec,
5253
(options as typeof options & { context: any }).context,
5354
options.maxDepth,

0 commit comments

Comments
 (0)