Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -2328,11 +2328,6 @@ private static bool FilterApplyMethodBase(
#pragma warning restore CA1823
private IntPtr m_cache;
internal IntPtr m_handle;

internal static readonly RuntimeType ValueType = (RuntimeType)typeof(ValueType);

private static readonly RuntimeType ObjectType = (RuntimeType)typeof(object);
private static readonly RuntimeType StringType = (RuntimeType)typeof(string);
#endregion

#region Constructor
Expand Down Expand Up @@ -3264,7 +3259,7 @@ public override bool IsSubclassOf(Type type)
// pretty much everything is a subclass of object, even interfaces
// notice that interfaces are really odd because they do not have a BaseType
// yet IsSubclassOf(typeof(object)) returns true
if (rtType == ObjectType && rtType != this)
if (rtType == typeof(object) && rtType != this)
return true;

return false;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
<Compile Include="$(CoreClrProjectRoot)System.Private.CoreLib\src\System\Runtime\CompilerServices\RuntimeAsyncTaskContinuation.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="Internal\Runtime\CompilerHelpers\DelegateHelpers.cs" />
<Compile Include="Internal\Runtime\CompilerHelpers\LibraryInitializer.cs" />
<Compile Include="Internal\Runtime\CompilerHelpers\ReachabilityInstrumentationSupport.cs" />
<Compile Include="Internal\Runtime\CompilerHelpers\ReflectionHelpers.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace System.Runtime
{
internal static class Constants
{
public static readonly int ThunkDataSize = 2 * IntPtr.Size;
public static int ThunkDataSize => 2 * IntPtr.Size;
public static readonly int ThunkCodeSize = RuntimeImports.RhpGetThunkSize();
public static readonly int NumThunksPerBlock = RuntimeImports.RhpGetNumThunksPerBlock();
public static readonly int NumThunkBlocksPerMapping = RuntimeImports.RhpGetNumThunkBlocksPerMapping();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,9 @@ public override MethodIL EmitIL()
}
else
{
MethodDesc emptyObjectArrayMethod = Context.GetHelperEntryPoint("DelegateHelpers"u8, "GetEmptyObjectArray"u8);
MethodDesc emptyObjectArrayMethod = Context.SystemModule.GetKnownType("System"u8, "Array"u8)
.GetKnownMethod("Empty"u8, null)
.MakeInstantiatedMethod(objectType);
codeStream.Emit(ILOpcode.call, emitter.NewToken(emptyObjectArrayMethod));
codeStream.EmitStLoc(argsLocal);
}
Expand Down
58 changes: 29 additions & 29 deletions src/libraries/System.Private.CoreLib/src/System/Decimal.DecCalc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -863,15 +863,14 @@ private static int SearchScale(ulong resMidLo, uint resHi, int scale)
goto HaveScale;
}

PowerOvfl[] powerOvfl = PowerOvflValues;
if (scale > DEC_SCALE_MAX - 9)
{
// We can't scale by 10^9 without exceeding the max scale factor.
// See if we can scale to the max. If not, we'll fall into
// standard search for scale factor.
//
curScale = DEC_SCALE_MAX - scale;
if (resHi < powerOvfl[curScale - 1].Hi)
if (resHi < PowerOvflHi[curScale - 1])
goto HaveScale;
}
else if (resHi < OVFL_MAX_9_HI || resHi == OVFL_MAX_9_HI && resMidLo <= OVFL_MAX_9_MIDLO)
Expand Down Expand Up @@ -915,7 +914,7 @@ private static int SearchScale(ulong resMidLo, uint resHi, int scale)
// we can't use this power, the one below it is correct for all cases
// unless it's 10^1 -- we might have to go to 10^0 (no scaling).
//
if (resHi == powerOvfl[curScale - 1].Hi && resMidLo > powerOvfl[curScale - 1].MidLo)
if (resHi == PowerOvflHi[curScale - 1] && resMidLo > PowerOvflMidLo[curScale - 1])
curScale--;

HaveScale:
Expand Down Expand Up @@ -2519,34 +2518,35 @@ internal static uint DecDivMod1E9(ref DecCalc value)
return (uint)num - div * TenToPowerNine;
}

private readonly struct PowerOvfl
{
public readonly uint Hi;
public readonly ulong MidLo;

public PowerOvfl(uint hi, uint mid, uint lo)
{
Hi = hi;
MidLo = ((ulong)mid << 32) + lo;
}
}
// This is a table of the largest values that can be in the upper two
// uints of a 96-bit number that will not overflow when multiplied
// by a given power. For the upper word, this is a table of
// 2^32 / 10^n for 1 <= n <= 8. For the lower word, this is the
// remaining fraction part * 2^32. 2^32 = 4294967296.
//
private static ReadOnlySpan<uint> PowerOvflHi =>
[
429496729, // 10^1 remainder 0.6
42949672, // 10^2 remainder 0.16
4294967, // 10^3 remainder 0.616
429496, // 10^4 remainder 0.1616
42949, // 10^5 remainder 0.51616
4294, // 10^6 remainder 0.551616
429, // 10^7 remainder 0.9551616
42, // 10^8 remainder 0.09991616
];

private static readonly PowerOvfl[] PowerOvflValues =
// ((ulong)mid << 32) + lo for each entry of PowerOvflHi
private static ReadOnlySpan<ulong> PowerOvflMidLo =>
[
// This is a table of the largest values that can be in the upper two
// uints of a 96-bit number that will not overflow when multiplied
// by a given power. For the upper word, this is a table of
// 2^32 / 10^n for 1 <= n <= 8. For the lower word, this is the
// remaining fraction part * 2^32. 2^32 = 4294967296.
//
new PowerOvfl(429496729, 2576980377, 2576980377), // 10^1 remainder 0.6
new PowerOvfl(42949672, 4123168604, 687194767), // 10^2 remainder 0.16
new PowerOvfl(4294967, 1271310319, 2645699854), // 10^3 remainder 0.616
new PowerOvfl(429496, 3133608139, 694066715), // 10^4 remainder 0.1616
new PowerOvfl(42949, 2890341191, 2216890319), // 10^5 remainder 0.51616
new PowerOvfl(4294, 4154504685, 2369172679), // 10^6 remainder 0.551616
new PowerOvfl(429, 2133437386, 4102387834), // 10^7 remainder 0.9551616
new PowerOvfl(42, 4078814305, 410238783), // 10^8 remainder 0.09991616
(2576980377UL << 32) + 2576980377,
(4123168604UL << 32) + 687194767,
(1271310319UL << 32) + 2645699854,
(3133608139UL << 32) + 694066715,
(2890341191UL << 32) + 2216890319,
(4154504685UL << 32) + 2369172679,
(2133437386UL << 32) + 4102387834,
(4078814305UL << 32) + 410238783,
];

[StructLayout(LayoutKind.Explicit, Pack = sizeof(uint))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ internal static class Statics
public const byte OutTypeChainFlag = 128;
public const EventTags EventTagsMask = (EventTags)0xfffffff;

public static readonly TraceLoggingDataType IntPtrType = IntPtr.Size == 8
public static TraceLoggingDataType IntPtrType => IntPtr.Size == 8
? TraceLoggingDataType.Int64
: TraceLoggingDataType.Int32;
public static readonly TraceLoggingDataType UIntPtrType = IntPtr.Size == 8
public static TraceLoggingDataType UIntPtrType => IntPtr.Size == 8
? TraceLoggingDataType.UInt64
: TraceLoggingDataType.UInt32;
public static readonly TraceLoggingDataType HexIntPtrType = IntPtr.Size == 8
public static TraceLoggingDataType HexIntPtrType => IntPtr.Size == 8
? TraceLoggingDataType.HexInt64
: TraceLoggingDataType.HexInt32;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -57,26 +56,26 @@ public XplatEventLogger() { }
[LibraryImport(RuntimeHelpers.QCall, StringMarshalling = StringMarshalling.Utf16)]
private static partial void LogEventSource(int eventID, string? eventName, string eventSourceName, string payload);

private static readonly List<char> escape_seq = new List<char> { '\b', '\f', '\n', '\r', '\t', '\"', '\\' };
private static readonly Dictionary<char, string> seq_mapping = new Dictionary<char, string>()
{
{'\b', "b"},
{'\f', "f"},
{'\n', "n"},
{'\r', "r"},
{'\t', "t"},
{'\"', "\\\""},
{'\\', "\\\\"}
};

private static void MinimalJsonserializer(string payload, ref ValueStringBuilder sb)
{
foreach (var elem in payload)
foreach (char elem in payload)
{
if (escape_seq.Contains(elem))
string? escaped = elem switch
{
'\b' => "b",
'\f' => "f",
'\n' => "n",
'\r' => "r",
'\t' => "t",
'\"' => "\\\"",
'\\' => "\\\\",
_ => null,
};

if (escaped is not null)
{
sb.Append("\\\\");
sb.Append(seq_mapping[elem]);
sb.Append(escaped);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1724,46 +1724,6 @@ private static bool TryConvertTo<TOther>(Decimal128 value, [MaybeNullWhen(false)
}
}


private static readonly UInt128[] UInt128Powers10 =
[
new UInt128(0, 1),
new UInt128(0, 10),
new UInt128(0, 100),
new UInt128(0, 1000),
new UInt128(0, 10000),
new UInt128(0, 100000),
new UInt128(0, 1000000),
new UInt128(0, 10000000),
new UInt128(0, 100000000),
new UInt128(0, 1000000000),
new UInt128(0, 10000000000),
new UInt128(0, 100000000000),
new UInt128(0, 1000000000000),
new UInt128(0, 10000000000000),
new UInt128(0, 100000000000000),
new UInt128(0, 1000000000000000),
new UInt128(0, 10000000000000000),
new UInt128(0, 100000000000000000),
new UInt128(0, 1000000000000000000),
new UInt128(0, 10000000000000000000),
new UInt128(5, 7766279631452241920),
new UInt128(54, 3875820019684212736),
new UInt128(542, 1864712049423024128),
new UInt128(5421, 200376420520689664),
new UInt128(54210, 2003764205206896640),
new UInt128(542101, 1590897978359414784),
new UInt128(5421010, 15908979783594147840),
new UInt128(54210108, 11515845246265065472),
new UInt128(542101086, 4477988020393345024),
new UInt128(5421010862, 7886392056514347008),
new UInt128(54210108624, 5076944270305263616),
new UInt128(542101086242, 13875954555633532928),
new UInt128(5421010862427, 9632337040368467968),
new UInt128(54210108624275, 4089650035136921600),
new UInt128(542101086242752, 4003012203950112768),
];

static string IDecimalIeee754ParseAndFormatInfo<Decimal128, UInt128>.ToDecStr(UInt128 significand)
{
return Number.UInt128ToDecStr(significand);
Expand All @@ -1786,11 +1746,11 @@ static UInt128 IDecimalIeee754ParseAndFormatInfo<Decimal128, UInt128>.NumberToSi

static int IDecimalIeee754ParseAndFormatInfo<Decimal128, UInt128>.ConvertToExponent(UInt128 value) => (int)value;

static UInt128 IDecimalIeee754ParseAndFormatInfo<Decimal128, UInt128>.Power10(int exponent) => UInt128Powers10[exponent];
static UInt128 IDecimalIeee754ParseAndFormatInfo<Decimal128, UInt128>.Power10(int exponent) => UInt128.PowersOf10[exponent];

static (UInt128 Quotient, UInt128 Remainder) IDecimalIeee754ParseAndFormatInfo<Decimal128, UInt128>.DivRemPow10(UInt128 value, int exponent)
{
UInt128 power = UInt128Powers10[exponent];
UInt128 power = UInt128.PowersOf10[exponent];
return UInt128.DivRem(value, power);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ _ when vt.HasFlag(VarEnum.VT_ARRAY) && sizeof(T) == nint.Size => rawValue,
/// <summary>
/// A <see cref="ComVariant"/> instance that represents a null value with <see cref="VarEnum.VT_NULL"/> type.
/// </summary>
public static ComVariant Null { get; } = new() { VarType = VarEnum.VT_NULL };
public static ComVariant Null => new() { VarType = VarEnum.VT_NULL };

private readonly void ThrowIfNotVarType(params ReadOnlySpan<VarEnum> requiredType)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ namespace System.Runtime.InteropServices
[ComVisible(true)]
public class StandardOleMarshalObject : MarshalByRefObject, IMarshal
{
private static readonly Guid CLSID_StdMarshal = new Guid("00000017-0000-0000-c000-000000000046");
// {00000017-0000-0000-c000-000000000046}
private static Guid CLSID_StdMarshal => new Guid(0x00000017, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);

protected StandardOleMarshalObject()
{
Expand Down
10 changes: 5 additions & 5 deletions src/libraries/System.Private.CoreLib/src/System/RuntimeType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public override int GetArrayRank()

public override object[] GetCustomAttributes(bool inherit)
{
return RuntimeCustomAttribute.GetCustomAttributes(this, ObjectType, inherit);
return RuntimeCustomAttribute.GetCustomAttributes(this, (RuntimeType)typeof(object), inherit);
}

public override object[] GetCustomAttributes(Type attributeType, bool inherit)
Expand Down Expand Up @@ -234,7 +234,7 @@ public override bool IsEnumDefined(object value)
}

// If a string is passed in, search the enum names with it.
if (valueType == StringType)
if (valueType == typeof(string))
return Array.IndexOf(Enum.GetNamesNoCopy(this), (string)value) >= 0;

// If an enum or integer value is passed in
Expand Down Expand Up @@ -716,7 +716,7 @@ public override bool IsAssignableFrom([NotNullWhen(true)] Type? c)
{
Type[] constraints = GetGenericParameterConstraints();

RuntimeType baseType = ObjectType;
RuntimeType baseType = (RuntimeType)typeof(object);

for (int i = 0; i < constraints.Length; i++)
{
Expand All @@ -737,11 +737,11 @@ public override bool IsAssignableFrom([NotNullWhen(true)] Type? c)
baseType = constraint;
}

if (baseType == ObjectType)
if (baseType == typeof(object))
{
GenericParameterAttributes special = GenericParameterAttributes;
if ((special & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0)
baseType = ValueType;
baseType = (RuntimeType)typeof(ValueType);
}

return baseType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public sealed partial class TimeZoneInfo
[Serializable]
public sealed class AdjustmentRule : IEquatable<AdjustmentRule?>, ISerializable, IDeserializationCallback
{
private static readonly TimeSpan DaylightDeltaAdjustment = TimeSpan.FromHours(24.0);
private static readonly TimeSpan MaxDaylightDelta = TimeSpan.FromHours(12.0);
private static TimeSpan DaylightDeltaAdjustment => new TimeSpan(24 * TimeSpan.TicksPerHour);
private static TimeSpan MaxDaylightDelta => new TimeSpan(12 * TimeSpan.TicksPerHour);
private readonly DateTime _dateStart;
private readonly DateTime _dateEnd;
private readonly TimeSpan _daylightDelta;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,12 +535,8 @@ private static bool FilterApplyMethodBase(

#region Private Data Members

internal static readonly RuntimeType ValueType = (RuntimeType)typeof(System.ValueType);
internal static readonly RuntimeType EnumType = (RuntimeType)typeof(System.Enum);

private static readonly RuntimeType ObjectType = (RuntimeType)typeof(object);
private static readonly RuntimeType StringType = (RuntimeType)typeof(string);

#endregion

#region Constructor
Expand Down
Loading