Skip to content

Commit

Permalink
Compute formatters only if elements are there
Browse files Browse the repository at this point in the history
  • Loading branch information
nmi-relewise committed Apr 22, 2024
1 parent fb0bb13 commit 6b4beaf
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ public void Serialize(ref MessagePackWriter writer, TDictionary? value, MessageP
}
else
{
IFormatterResolver resolver = options.Resolver;
IMessagePackFormatter<TKey>? keyFormatter = resolver.GetFormatterWithVerify<TKey>();
IMessagePackFormatter<TValue>? valueFormatter = resolver.GetFormatterWithVerify<TValue>();

var len = reader.ReadMapHeader();

TIntermediate dict = this.Create(len, options);
Expand All @@ -90,6 +86,9 @@ public void Serialize(ref MessagePackWriter writer, TDictionary? value, MessageP
{
if (len > 0)
{
IFormatterResolver resolver = options.Resolver;
IMessagePackFormatter<TKey>? keyFormatter = resolver.GetFormatterWithVerify<TKey>();
IMessagePackFormatter<TValue>? valueFormatter = resolver.GetFormatterWithVerify<TValue>();
for (int i = 0; i < len; i++)
{
reader.CancellationToken.ThrowIfCancellationRequested();
Expand Down

0 comments on commit 6b4beaf

Please sign in to comment.