Skip to content

Commit

Permalink
encode minor performance optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
buu700 committed May 4, 2021
1 parent c66d264 commit 44db5ec
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/encode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type EncodeOptions<ContextType = undefined> = Partial<
ContextOf<ContextType>;

const defaultEncodeOptions: EncodeOptions = {};
const defaultEncoder = new Encoder();

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

0 comments on commit 44db5ec

Please sign in to comment.