Skip to content

Commit

Permalink
[NRBF] Remove array allocation when decoding decimals. (#107797)
Browse files Browse the repository at this point in the history
By directly passing a collection expression to `decimal`'s constructor, we avoid allocating an array on frameworks that have an overload that accepts a `ReadOnlySpan<int>`, in which case the span's memory is allocated on the stack.
  • Loading branch information
teo-tsirpanis committed Sep 20, 2024
1 parent f968980 commit 89f245e
Showing 1 changed file with 1 addition and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,7 @@ ulong value when TypeNameMatches(typeof(UIntPtr)) => Create(new UIntPtr(value)),
&& GetRawValue("hi") is int hi && GetRawValue("flags") is int flags
&& TypeNameMatches(typeof(decimal)))
{
int[] bits =
[
lo,
mid,
hi,
flags
];

return Create(new decimal(bits));
return Create(new decimal([lo, mid, hi, flags]));
}

return this;
Expand Down

0 comments on commit 89f245e

Please sign in to comment.