Skip to content

Commit

Permalink
make value type a ref
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhathcock committed Nov 15, 2024
1 parent 1793ab1 commit b95129f
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/Speckle.Sdk/Serialisation/V2/Receive/ObjectDeserializer2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Base Deserialize(string objectJson)
try
{
reader.Read();
converted = (Base)ReadObject(reader).NotNull();
converted = (Base)ReadObject(ref reader).NotNull();
}
catch (Exception ex) when (!ex.IsFatal() && ex is not OperationCanceledException)
{
Expand All @@ -43,13 +43,13 @@ public Base Deserialize(string objectJson)
return converted;
}

private List<object?> ReadArrayAsync(Utf8JsonReader reader)
private List<object?> ReadArrayAsync(ref Utf8JsonReader reader)
{
reader.Read();
List<object?> retList = new();
while (reader.TokenType != JsonTokenType.EndArray)
{
object? convertedValue = ReadProperty(reader);
object? convertedValue = ReadProperty(ref reader);
if (convertedValue is DataChunk chunk)
{
retList.AddRange(chunk.data);
Expand All @@ -63,7 +63,7 @@ public Base Deserialize(string objectJson)
return retList;
}

private object? ReadObject(Utf8JsonReader reader)
private object? ReadObject(ref Utf8JsonReader reader)
{
reader.Read();
Dictionary<string, object?> dict = Pools.ObjectDictionaries.Get();
Expand All @@ -75,13 +75,15 @@ public Base Deserialize(string objectJson)
{
var propName = reader.GetString().NotNull();
reader.Read(); //goes prop value
object? convertedValue = ReadProperty(reader);
object? convertedValue = ReadProperty(ref reader);
dict[propName] = convertedValue;
reader.Read(); //goes to next
}
break;
default:
throw new InvalidOperationException($"Unknown {reader.TokenType} with {reader.GetString()}");
throw new InvalidOperationException(
$"Unknown {reader.TokenType} with {Encoding.UTF8.GetString(reader.ValueSpan)}"
);
}
}

Expand Down Expand Up @@ -111,7 +113,7 @@ public Base Deserialize(string objectJson)
return b;
}

private object? ReadProperty(Utf8JsonReader reader)
private object? ReadProperty(ref Utf8JsonReader reader)
{
switch (reader.TokenType)
{
Expand Down Expand Up @@ -144,9 +146,9 @@ public Base Deserialize(string objectJson)
}
return reader.GetString();
case JsonTokenType.StartArray:
return ReadArrayAsync(reader);
return ReadArrayAsync(ref reader);
case JsonTokenType.StartObject:
var dict = ReadObject(reader);
var dict = ReadObject(ref reader);
return dict;

default:
Expand Down

0 comments on commit b95129f

Please sign in to comment.