From 89f245e722eda87869dbb04690cb91361af8174c Mon Sep 17 00:00:00 2001 From: Theodore Tsirpanis Date: Fri, 20 Sep 2024 11:14:54 +0300 Subject: [PATCH] [NRBF] Remove array allocation when decoding `decimal`s. (#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`, in which case the span's memory is allocated on the stack. --- .../Nrbf/SystemClassWithMembersAndTypesRecord.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/SystemClassWithMembersAndTypesRecord.cs b/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/SystemClassWithMembersAndTypesRecord.cs index ccecc2246e8c2..2a5f7b945ce85 100644 --- a/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/SystemClassWithMembersAndTypesRecord.cs +++ b/src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/SystemClassWithMembersAndTypesRecord.cs @@ -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;