Background and motivation
Currently, many members in CultureInfo and NumberFormatInfo returns array. Because the lack of immutable array in the first play, these members have to return a copy of the array. To avoid the allocation, many members in CoreLib are accessing the storage directly and bypassing the copy (For example #84964). However, types outside CoreLib can't benefit from this. This is currently mainly affecting BigInteger.
API Proposal
namespace System.Globalization;
public sealed class NumberFormatInfo
{
public int[] CurrencyGroupSizes { get; set; }
+ public ReadOnlySpan<int> CurrencyGroupSizesValue { get; }
public int[] NumberGroupSizes { get; set; }
+ public ReadOnlySpan<int> NumberGroupSizesValue { get; }
public int[] PercentGroupSizes { get; set; }
+ public ReadOnlySpan<int> PercentGroupSizesValue { get; }
public string[] NativeDigits { get; set; }
+ public ReadOnlySpan<string> NativeDigitsValue { get; }
}
public sealed class DateTimeFormatInfo
{
public string[] AbbreviatedDayNames { get; set; }
+ public ReadOnlySpan<string> AbbreviatedDayNamesValue { get; }
public string[] AbbreviatedMonthGenitiveNames { get; set; }
+ public ReadOnlySpan<string> AbbreviatedMonthGenitiveNames Value { get; }
// ... more similar member omitted
}
API Usage
Replacing the following direct access of storage array in CoreLib:
int[] groupDigits = info._numberGroupSizes;
Alternative Designs
Use different return types like IReadOnlyList<T>? ImmutableArray<T> isn't an option here since it doesn't live in CoreLib.
Are these members, especially DateTimeFormatInfo used wide enough outside CoreLib?
Risks
No response
Background and motivation
Currently, many members in
CultureInfoandNumberFormatInforeturns array. Because the lack of immutable array in the first play, these members have to return a copy of the array. To avoid the allocation, many members in CoreLib are accessing the storage directly and bypassing the copy (For example #84964). However, types outside CoreLib can't benefit from this. This is currently mainly affectingBigInteger.API Proposal
namespace System.Globalization; public sealed class NumberFormatInfo { public int[] CurrencyGroupSizes { get; set; } + public ReadOnlySpan<int> CurrencyGroupSizesValue { get; } public int[] NumberGroupSizes { get; set; } + public ReadOnlySpan<int> NumberGroupSizesValue { get; } public int[] PercentGroupSizes { get; set; } + public ReadOnlySpan<int> PercentGroupSizesValue { get; } public string[] NativeDigits { get; set; } + public ReadOnlySpan<string> NativeDigitsValue { get; } } public sealed class DateTimeFormatInfo { public string[] AbbreviatedDayNames { get; set; } + public ReadOnlySpan<string> AbbreviatedDayNamesValue { get; } public string[] AbbreviatedMonthGenitiveNames { get; set; } + public ReadOnlySpan<string> AbbreviatedMonthGenitiveNames Value { get; } // ... more similar member omitted }API Usage
Replacing the following direct access of storage array in CoreLib:
Alternative Designs
Use different return types like
IReadOnlyList<T>?ImmutableArray<T>isn't an option here since it doesn't live in CoreLib.Are these members, especially
DateTimeFormatInfoused wide enough outside CoreLib?Risks
No response