Skip to content

Commit 89f245e

Browse files
[NRBF] Remove array allocation when decoding decimals. (#107797)
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.
1 parent f968980 commit 89f245e

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/SystemClassWithMembersAndTypesRecord.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,7 @@ ulong value when TypeNameMatches(typeof(UIntPtr)) => Create(new UIntPtr(value)),
9393
&& GetRawValue("hi") is int hi && GetRawValue("flags") is int flags
9494
&& TypeNameMatches(typeof(decimal)))
9595
{
96-
int[] bits =
97-
[
98-
lo,
99-
mid,
100-
hi,
101-
flags
102-
];
103-
104-
return Create(new decimal(bits));
96+
return Create(new decimal([lo, mid, hi, flags]));
10597
}
10698

10799
return this;

0 commit comments

Comments
 (0)