Skip to content

Commit

Permalink
Make CompositeNodeIdValueSerializer more efficient by removing nullab…
Browse files Browse the repository at this point in the history
…les.
  • Loading branch information
michaelstaib committed Apr 5, 2024
1 parent df07a91 commit 0bfd72c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ protected static unsafe bool TryParseIdPart(
/// </returns>
protected static bool TryParseIdPart(
ReadOnlySpan<byte> buffer,
[NotNullWhen(true)] out Guid? value,
out Guid value,
out int consumed,
bool compress = true)
{
Expand All @@ -387,7 +387,7 @@ protected static bool TryParseIdPart(
{
if (valueSpan.Length != 16)
{
value = null;
value = default;
consumed = 0;
return false;
}
Expand All @@ -408,7 +408,7 @@ protected static bool TryParseIdPart(
return true;
}

value = null;
value = default;
consumed = 0;
return false;
}
Expand All @@ -430,7 +430,7 @@ protected static bool TryParseIdPart(
/// </returns>
protected static bool TryParseIdPart(
ReadOnlySpan<byte> buffer,
[NotNullWhen(true)] out short? value,
out short value,
out int consumed)
{
var index = buffer.IndexOf(_partSeparator);
Expand All @@ -443,7 +443,7 @@ protected static bool TryParseIdPart(
return true;
}

value = null;
value = default;
consumed = 0;
return false;
}
Expand All @@ -465,7 +465,7 @@ protected static bool TryParseIdPart(
/// </returns>
protected static bool TryParseIdPart(
ReadOnlySpan<byte> buffer,
[NotNullWhen(true)] out int? value,
out int value,
out int consumed)
{
var index = buffer.IndexOf(_partSeparator);
Expand All @@ -478,7 +478,7 @@ protected static bool TryParseIdPart(
return true;
}

value = null;
value = default;
consumed = 0;
return false;
}
Expand All @@ -500,7 +500,7 @@ protected static bool TryParseIdPart(
/// </returns>
protected static bool TryParseIdPart(
ReadOnlySpan<byte> buffer,
[NotNullWhen(true)] out long? value,
out long value,
out int consumed)
{
var index = buffer.IndexOf(_partSeparator);
Expand All @@ -513,7 +513,7 @@ protected static bool TryParseIdPart(
return true;
}

value = null;
value = default;
consumed = 0;
return false;
}
Expand All @@ -535,7 +535,7 @@ protected static bool TryParseIdPart(
/// </returns>
protected static bool TryParseIdPart(
ReadOnlySpan<byte> buffer,
[NotNullWhen(true)] out bool? value,
out bool value,
out int consumed)
{
var index = buffer.IndexOf(_partSeparator);
Expand All @@ -548,7 +548,7 @@ protected static bool TryParseIdPart(
return true;
}

value = null;
value = default;
consumed = 0;
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ protected override NodeIdFormatterResult Format(Span<byte> buffer, CompositeId v
protected override bool TryParse(ReadOnlySpan<byte> buffer, out CompositeId value)
{
if(TryParseIdPart(buffer, out string a, out var ac) &&
TryParseIdPart(buffer.Slice(ac), out int? b, out var bc) &&
TryParseIdPart(buffer.Slice(ac + bc), out Guid? c, out var cc) &&
TryParseIdPart(buffer.Slice(ac + bc + cc), out bool? d, out _))
TryParseIdPart(buffer.Slice(ac), out int b, out var bc) &&
TryParseIdPart(buffer.Slice(ac + bc), out Guid c, out var cc) &&
TryParseIdPart(buffer.Slice(ac + bc + cc), out bool d, out _))
{
value = new CompositeId(a, b.Value, c.Value, d.Value);
value = new CompositeId(a, b, c, d);
return true;
}

Expand Down

0 comments on commit 0bfd72c

Please sign in to comment.