Skip to content

Commit

Permalink
Merge pull request #1805 from nmi-relewise/feature/1804-locate-format…
Browse files Browse the repository at this point in the history
…ters-only-if-has-elements-inside
  • Loading branch information
AArnott committed Apr 24, 2024
2 parents 43f1b1c + 6b4beaf commit 92d6365
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Expand Up @@ -78,24 +78,26 @@ 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);
options.Security.DepthStep(ref reader);
try
{
for (int i = 0; i < len; i++)
if (len > 0)
{
reader.CancellationToken.ThrowIfCancellationRequested();
TKey key = keyFormatter.Deserialize(ref reader, options);
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();
TKey key = keyFormatter.Deserialize(ref reader, options);

TValue value = valueFormatter.Deserialize(ref reader, options);
TValue value = valueFormatter.Deserialize(ref reader, options);

this.Add(dict, i, key, value, options);
this.Add(dict, i, key, value, options);
}
}
}
finally
Expand Down
Expand Up @@ -53,12 +53,14 @@ public void InterfaceDictionaryTest()
public void ConcurrentDictionaryTest()
{
var cd = new ConcurrentDictionary<int, int>();
ConcurrentDictionary<int, int> conv = this.Convert(cd);
conv.Count.Is(0);

cd.TryAdd(1, 100);
cd.TryAdd(2, 200);
cd.TryAdd(3, 300);

ConcurrentDictionary<int, int> conv = this.Convert(cd);
conv = this.Convert(cd);
conv[1].Is(100);
conv[2].Is(200);
conv[3].Is(300);
Expand Down

0 comments on commit 92d6365

Please sign in to comment.