Skip to content

Commit f18c88d

Browse files
Shrink hello world by 3.2% (#84463)
* Get rid of the MethodTable for double/float * Get rid of any `Array<T>` methods
1 parent 38b81ba commit f18c88d

File tree

4 files changed

+14
-32
lines changed

4 files changed

+14
-32
lines changed

src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/Execution/ExecutionDomain.cs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -251,28 +251,17 @@ public bool SupportsReflection(Type type)
251251
return true;
252252
}
253253

254+
public static bool IsPrimitiveType(Type type)
255+
=> type == typeof(bool) || type == typeof(char)
256+
|| type == typeof(sbyte) || type == typeof(byte)
257+
|| type == typeof(short) || type == typeof(ushort)
258+
|| type == typeof(int) || type == typeof(uint)
259+
|| type == typeof(long) || type == typeof(ulong)
260+
|| type == typeof(float) || type == typeof(double)
261+
|| type == typeof(nint) || type == typeof(nuint);
262+
254263
internal ExecutionEnvironment ExecutionEnvironment { get; }
255264

256265
internal ReflectionDomainSetup ReflectionDomainSetup { get; }
257-
258-
internal static IEnumerable<Type> PrimitiveTypes => s_primitiveTypes;
259-
260-
private static readonly Type[] s_primitiveTypes =
261-
{
262-
typeof(bool),
263-
typeof(char),
264-
typeof(sbyte),
265-
typeof(byte),
266-
typeof(short),
267-
typeof(ushort),
268-
typeof(int),
269-
typeof(uint),
270-
typeof(long),
271-
typeof(ulong),
272-
typeof(float),
273-
typeof(double),
274-
typeof(IntPtr),
275-
typeof(UIntPtr),
276-
};
277266
}
278267
}

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -833,14 +833,8 @@ static Type GetLimitedBaseType(RuntimeTypeInfo thisType)
833833
if (baseType == valueType && this != enumType)
834834
{
835835
classification |= TypeClassification.IsValueType;
836-
foreach (Type primitiveType in ExecutionDomain.PrimitiveTypes)
837-
{
838-
if (this.Equals(primitiveType))
839-
{
840-
classification |= TypeClassification.IsPrimitive;
841-
break;
842-
}
843-
}
836+
if (ExecutionDomain.IsPrimitiveType(this))
837+
classification |= TypeClassification.IsPrimitive;
844838
}
845839
}
846840
_lazyClassification = classification;

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/RuntimeAssemblyName.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ public void CopyToAssemblyName(AssemblyName blank)
152152
{
153153
// We must not hand out our own copy of the PKT to AssemblyName as AssemblyName is amazingly trusting and gives untrusted callers
154154
// full freedom to scribble on its PKT array. (As do we but we only have trusted callers!)
155-
byte[] pkCopy = new byte[this.PublicKeyOrToken.Length];
156-
((ICollection<byte>)(this.PublicKeyOrToken)).CopyTo(pkCopy, 0);
155+
var pkCopy = (byte[])this.PublicKeyOrToken.Clone();
157156

158157
if (0 != (this.Flags & AssemblyNameFlags.PublicKey))
159158
blank.SetPublicKey(pkCopy);

src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/NativeFormatEnumInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ public static void GetEnumValuesAndNames(MetadataReader reader, TypeDefinitionHa
4343
var handle = field.DefaultValue;
4444
unsortedBoxedValues[i] = handle.HandleType switch
4545
{
46-
HandleType.ConstantSByteValue => (byte)handle.ToConstantSByteValueHandle(reader).GetConstantSByteValue(reader).Value,
46+
HandleType.ConstantSByteValue => (object)(byte)handle.ToConstantSByteValueHandle(reader).GetConstantSByteValue(reader).Value,
4747
HandleType.ConstantByteValue => handle.ToConstantByteValueHandle(reader).GetConstantByteValue(reader).Value,
4848
HandleType.ConstantInt16Value => (ushort)handle.ToConstantInt16ValueHandle(reader).GetConstantInt16Value(reader).Value,
4949
HandleType.ConstantUInt16Value => handle.ToConstantUInt16ValueHandle(reader).GetConstantUInt16Value(reader).Value,
5050
HandleType.ConstantInt32Value => (uint)handle.ToConstantInt32ValueHandle(reader).GetConstantInt32Value(reader).Value,
5151
HandleType.ConstantUInt32Value => handle.ToConstantUInt32ValueHandle(reader).GetConstantUInt32Value(reader).Value,
5252
HandleType.ConstantInt64Value => (ulong)handle.ToConstantInt64ValueHandle(reader).GetConstantInt64Value(reader).Value,
5353
HandleType.ConstantUInt64Value => handle.ToConstantUInt64ValueHandle(reader).GetConstantUInt64Value(reader).Value,
54-
_ => handle.ParseConstantNumericValue(reader), // fallback for unhandled cases
54+
_ => throw new InvalidOperationException(), // unreachable - we would have thrown InvalidOperationException earlier
5555
};
5656
i++;
5757
}

0 commit comments

Comments
 (0)