Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal bool IsEnum

// Generic type definitions that return true for IsPrimitive are type definitions of generic enums.
// Otherwise check the base type.
return IsPrimitive && (IsGenericTypeDefinition || NonArrayBaseType == MethodTable.Of<Enum>());
return IsPrimitive && (IsGenericTypeDefinition || NonArrayBaseType != MethodTable.Of<ValueType>());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ public static long GetTotalAllocatedBytes(bool precise = false)

/// <summary>Gets garbage collection memory information.</summary>
/// <returns>An object that contains information about the garbage collector's memory usage.</returns>
public static GCMemoryInfo GetGCMemoryInfo() => GetGCMemoryInfo(GCKind.Any);
public static GCMemoryInfo GetGCMemoryInfo() => GetGCMemoryInfoUnchecked(GCKind.Any);

/// <summary>Gets garbage collection memory information.</summary>
/// <param name="kind">The kind of collection for which to retrieve memory information.</param>
Expand All @@ -780,6 +780,11 @@ public static GCMemoryInfo GetGCMemoryInfo(GCKind kind)
GCKind.Background));
}

return GetGCMemoryInfoUnchecked(kind);
}

private static GCMemoryInfo GetGCMemoryInfoUnchecked(GCKind kind)
{
var data = new GCMemoryInfoData();
RuntimeImports.RhGetMemoryInfo(ref data.GetRawData(), kind);
return new GCMemoryInfo(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,14 @@ private bool SetApartmentStateUnchecked(ApartmentState state, bool throwOnError)
{
if (throwOnError)
{
string msg = SR.Format(SR.Thread_ApartmentState_ChangeFailed, retState);
// NOTE: We do the enum stringification manually to avoid introducing a dependency
// on enum stringification in small apps. We set apartment state in the startup path.
string msg = SR.Format(SR.Thread_ApartmentState_ChangeFailed, retState switch
{
ApartmentState.MTA => "MTA",
ApartmentState.STA => "STA",
_ => "Unknown"
});
throw new InvalidOperationException(msg);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,34 @@ internal static CultureInfo[] GetCultures(CultureTypes types)
return GlobalizationMode.UseNls ? NlsEnumCultures(types) : IcuEnumCultures(types);
}

private static CalendarId[] GetInvariantCalendarIdArray() => [CalendarId.GREGORIAN];
private static CalendarData[] GetInvariantCalendarDataArray()
{
var calendars = new CalendarData[CalendarData.MAX_CALENDARS];
calendars[0] = CalendarData.Invariant;
return calendars;
}

private static CultureData CreateCultureWithInvariantData()
{
CultureData invariant = CreateCultureWithInvariantDataWithoutCalendars();

// all available calendar type(s). The first one is the default calendar
invariant._waCalendars = GetInvariantCalendarIdArray();

if (!GlobalizationMode.InvariantNoLoad)
{
invariant._calendars = GetInvariantCalendarDataArray();
}

return invariant;
}

// Calendar information is expensive size-wise, especially for AOT.
// CalendarData.Invariant is special cased in _waCalendars and _calendars
// accessors and gets initialized lazily. All other uses should use
// CreateCultureWithInvariantData above that populates calendars too.
private static CultureData CreateCultureWithInvariantDataWithoutCalendars()
{
// Make a new culturedata
CultureData invariant = new CultureData();
Expand Down Expand Up @@ -625,16 +652,6 @@ private static CultureData CreateCultureWithInvariantData()
invariant._iFirstDayOfWeek = 0; // first day of week
invariant._iFirstWeekOfYear = 0; // first week of year

// all available calendar type(s). The first one is the default calendar
invariant._waCalendars = [CalendarId.GREGORIAN];

if (!GlobalizationMode.InvariantNoLoad)
{
// Store for specific data about each calendar
invariant._calendars = new CalendarData[CalendarData.MAX_CALENDARS];
invariant._calendars[0] = CalendarData.Invariant;
}

// Text information
invariant._iReadingLayout = 0;

Expand All @@ -658,7 +675,7 @@ private static CultureData CreateCultureWithInvariantData()
/// Build our invariant information
/// We need an invariant instance, which we build hard-coded
/// </summary>
internal static CultureData Invariant => field ??= CreateCultureWithInvariantData();
internal static CultureData Invariant => field ??= CreateCultureWithInvariantDataWithoutCalendars();

// Cache of cultures we've already looked up
private static volatile Dictionary<string, CultureData>? s_cachedCultures;
Expand Down Expand Up @@ -1647,7 +1664,13 @@ internal CalendarId[] CalendarIds
{
get
{
if (_waCalendars == null && !GlobalizationMode.Invariant)
if (_waCalendars == null && this == Invariant)
{
// We do this lazily as opposed in CreateCultureWithInvariantData to avoid introducing
// enum arrays into apps that otherwise wouldn't have them. This helps with size in AOT.
_waCalendars = GetInvariantCalendarIdArray();
}
else if (_waCalendars == null && !GlobalizationMode.Invariant)
{
// We pass in an array of ints, and native side fills it up with count calendars.
// We then have to copy that list to a new array of the right size.
Expand All @@ -1660,8 +1683,8 @@ internal CalendarId[] CalendarIds
// See if we had a calendar to add.
if (count == 0)
{
// Failed for some reason, just grab Gregorian from Invariant
_waCalendars = Invariant._waCalendars!;
// Failed for some reason, just use Gregorian
_waCalendars = GetInvariantCalendarIdArray();
}
else
{
Expand Down Expand Up @@ -1727,6 +1750,13 @@ internal CalendarData GetCalendar(CalendarId calendarId)
// arrays are 0 based, calendarIds are 1 based
int calendarIndex = (int)calendarId - 1;

if (_calendars == null && this == Invariant)
{
// We do this lazily as opposed in CreateCultureWithInvariantData to avoid introducing
// invariant calendar data into apps that don't even need calendar.
_calendars = GetInvariantCalendarDataArray();
}

// Have to have calendars
_calendars ??= new CalendarData[CalendarData.MAX_CALENDARS];

Expand Down
Loading