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 @@ -391,7 +391,7 @@ private static Type[] GetIndexParameterTypes(PropertyInfo element)
return indexParamTypes;
}

return Type.EmptyTypes;
return [];
}

private static void AddAttributesToList(List<Attribute> attributeList, Attribute[] attributes, Dictionary<Type, AttributeUsageAttribute> types)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1259,13 +1259,13 @@ private RuntimeConstructorBuilder DefineDefaultConstructorNoLock(MethodAttribute

if (inst is TypeBuilderInstantiation)
con = GetConstructor(inst, genericTypeDefinition.GetConstructor(
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, EmptyTypes, null)!);
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, [], null)!);
else
con = inst.GetConstructor(
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, EmptyTypes, null);
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, [], null);
}

con ??= m_typeParent!.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, EmptyTypes, null);
con ??= m_typeParent!.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, [], null);

if (con == null)
throw new NotSupportedException(SR.NotSupported_NoParentDefaultConstructor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,9 @@ public override Type FieldType
}
}

public override Type[] GetRequiredCustomModifiers()
{
return Type.EmptyTypes;
}
public override Type[] GetRequiredCustomModifiers() => [];

public override Type[] GetOptionalCustomModifiers()
{
return Type.EmptyTypes;
}
public override Type[] GetOptionalCustomModifiers() => [];

#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ internal static Type Create(Type unmodifiedType, Signature? signature, int param

private Type[] GetCustomModifiers(bool required) =>
(_typeSignature._signature != null) ?
_typeSignature._signature.GetCustomModifiersAtOffset(_typeSignature._offset, required) : EmptyTypes;
_typeSignature._signature.GetCustomModifiersAtOffset(_typeSignature._offset, required) : [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,7 @@ private static void AddCustomAttributes(

RuntimePropertyInfo? property = (RuntimePropertyInfo?)(type is null ?
attributeType.GetProperty(name) :
attributeType.GetProperty(name, type, Type.EmptyTypes)) ??
attributeType.GetProperty(name, type, [])) ??
throw new CustomAttributeFormatException(SR.Format(SR.RFLCT_InvalidPropFail, name));
RuntimeMethodInfo setMethod = property.GetSetMethod(true)!;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ internal RuntimeType[] GetGenericArgumentsInternal() =>
RuntimeMethodHandle.GetMethodInstantiationInternal(this);

public override Type[] GetGenericArguments() =>
RuntimeMethodHandle.GetMethodInstantiationPublic(this) ?? Type.EmptyTypes;
RuntimeMethodHandle.GetMethodInstantiationPublic(this) ?? [];

public override MethodInfo GetGenericMethodDefinition()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public override bool HasDefaultValue
if (IsOptional)
{
// If the argument is marked as optional then the default value is Missing.Value.
defaultValue = Type.Missing;
defaultValue = Missing.Value;
}
#endregion
}
Expand Down Expand Up @@ -434,16 +434,12 @@ private static DateTime GetRawDateTimeConstant(CustomAttributeData attr)

public override Type[] GetRequiredCustomModifiers()
{
return m_signature is null ?
Type.EmptyTypes :
m_signature.GetCustomModifiers(PositionImpl + 1, true);
return m_signature is null ? [] : m_signature.GetCustomModifiers(PositionImpl + 1, true);
}

public override Type[] GetOptionalCustomModifiers()
{
return m_signature is null ?
Type.EmptyTypes :
m_signature.GetCustomModifiers(PositionImpl + 1, false);
return m_signature is null ? [] : m_signature.GetCustomModifiers(PositionImpl + 1, false);
}

public override Type GetModifiedParameterType() =>
Expand Down
14 changes: 7 additions & 7 deletions src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -578,14 +578,14 @@ internal static Type[] GetInterfaces(RuntimeType type)
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "RuntimeTypeHandle_GetConstraints")]
private static partial void GetConstraints(QCallTypeHandle handle, ObjectHandleOnStack types);

internal Type[] GetConstraints()
internal Type[]? GetConstraints()
{
Type[]? types = null;
RuntimeTypeHandle nativeHandle = GetNativeHandle();

GetConstraints(new QCallTypeHandle(ref nativeHandle), ObjectHandleOnStack.Create(ref types));

return types!;
return types;
}

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "QCall_GetGCHandleForTypeHandle")]
Expand Down Expand Up @@ -744,12 +744,12 @@ internal RuntimeType[] GetInstantiationInternal()
return types!;
}

internal Type[] GetInstantiationPublic()
internal Type[]? GetInstantiationPublic()
{
Type[]? types = null;
RuntimeTypeHandle nativeHandle = GetNativeHandle();
GetInstantiation(new QCallTypeHandle(ref nativeHandle), ObjectHandleOnStack.Create(ref types), Interop.BOOL.FALSE);
return types!;
return types;
}

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "RuntimeTypeHandle_Instantiate")]
Expand Down Expand Up @@ -1229,12 +1229,12 @@ internal static RuntimeType[] GetMethodInstantiationInternal(RuntimeMethodHandle
return types!;
}

internal static Type[] GetMethodInstantiationPublic(IRuntimeMethodInfo method)
internal static Type[]? GetMethodInstantiationPublic(IRuntimeMethodInfo method)
{
RuntimeType[]? types = null;
Type[]? types = null;
GetMethodInstantiation(EnsureNonNullMethodInfo(method).Value, ObjectHandleOnStack.Create(ref types), Interop.BOOL.FALSE);
GC.KeepAlive(method);
return types!;
return types;
}

[MethodImpl(MethodImplOptions.InternalCall)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3542,8 +3542,7 @@ internal RuntimeType[] GetGenericArgumentsInternal()

public override Type[] GetGenericArguments()
{
Type[] types = GetRootElementType().TypeHandle.GetInstantiationPublic();
return types ?? EmptyTypes;
return GetRootElementType().TypeHandle.GetInstantiationPublic() ?? [];
}

[RequiresUnreferencedCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")]
Expand Down Expand Up @@ -3636,8 +3635,7 @@ public override Type[] GetGenericParameterConstraints()
if (!IsGenericParameter)
throw new InvalidOperationException(SR.Arg_NotGenericParameter);

Type[] constraints = new RuntimeTypeHandle(this).GetConstraints();
return constraints ?? EmptyTypes;
return new RuntimeTypeHandle(this).GetConstraints() ?? [];
}
#endregion

Expand Down Expand Up @@ -3756,7 +3754,7 @@ public override Type[] GetFunctionPointerCallingConventions()
}

// Requires a modified type to return the modifiers.
return EmptyTypes;
return [];
}

public override Type[] GetFunctionPointerParameterTypes()
Expand All @@ -3771,7 +3769,7 @@ public override Type[] GetFunctionPointerParameterTypes()

if (parameters.Length == 1)
{
return EmptyTypes;
return [];
}

return parameters.AsSpan(1).ToArray();
Expand Down Expand Up @@ -3844,7 +3842,7 @@ private void CreateInstanceCheckThis()
int consCount = 0;

// We cannot use Type.GetTypeArray here because some of the args might be null
Type[] argsType = args.Length != 0 ? new Type[args.Length] : EmptyTypes;
Type[] argsType = args.Length != 0 ? new Type[args.Length] : [];
for (int i = 0; i < args.Length; i++)
{
if (args[i] is object arg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public UnificationKey Key

public override Assembly Assembly => typeof(object).Assembly;
public override IEnumerable<CustomAttributeData> CustomAttributes => Array.Empty<CustomAttributeData>();
public override Type[] GetFunctionPointerCallingConventions() => Type.EmptyTypes;
public override Type[] GetFunctionPointerCallingConventions() => [];

public override bool ContainsGenericParameters
{
Expand Down Expand Up @@ -66,7 +66,7 @@ public override bool HasSameMetadataDefinitionAs(MemberInfo other)
public override Type[] GetFunctionPointerParameterTypes()
{
if (_key.ParameterTypes.Length == 0)
return Type.EmptyTypes;
return [];

Type[] result = new Type[_key.ParameterTypes.Length];
Array.Copy(_key.ParameterTypes, result, result.Length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public override Type[] GetInterfaces()
{
int count = pEEType->NumInterfaces;
if (count == 0)
return EmptyTypes;
return [];

Type[] result = new Type[count];
for (int i = 0; i < result.Length; i++)
Expand Down Expand Up @@ -426,7 +426,7 @@ public override Type[] GenericTypeArguments
if (pEEType != null)
{
if (!pEEType->IsGeneric)
return EmptyTypes;
return [];

MethodTableList genericArguments = pEEType->GenericArguments;

Expand All @@ -448,7 +448,7 @@ public override Type[] GetGenericArguments()
return GenericTypeArguments;
if (IsGenericTypeDefinition)
return GenericTypeParameters;
return EmptyTypes;
return [];
}

public override bool IsGenericParameter
Expand Down Expand Up @@ -565,7 +565,7 @@ public override Type[] GetFunctionPointerParameterTypes()

uint count = pEEType->NumFunctionPointerParameters;
if (count == 0)
return EmptyTypes;
return [];

MethodTableList parameterTypes = pEEType->FunctionPointerParameters;

Expand Down Expand Up @@ -690,7 +690,7 @@ public override Type[] GetFunctionPointerCallingConventions()
throw new InvalidOperationException(SR.InvalidOperation_NotFunctionPointer);

// Requires a modified type to return the modifiers.
return EmptyTypes;
return [];
}

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@ internal static unsafe RuntimeType GetTypeFromMethodTable(MethodTable* pMT)
return type ?? GetTypeFromMethodTableSlow(pMT);
}

private static class AllocationLockHolder
private static class AllocationLock
{
public static readonly Lock AllocationLock = new Lock(useTrivialWaits: true);
public static Lock Instance =>
field ?? Interlocked.CompareExchange(ref field, new Lock(useTrivialWaits: true), null) ?? field;
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static unsafe RuntimeType GetTypeFromMethodTableSlow(MethodTable* pMT)
{
// Allocate and set the RuntimeType under a lock - there's no way to free it if there is a race.
using (AllocationLockHolder.AllocationLock.EnterScope())
lock (AllocationLock.Instance)
{
ref RuntimeType? runtimeTypeCache = ref Unsafe.AsRef<RuntimeType?>(pMT->WritableData);
if (runtimeTypeCache != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public static object CreateInstance(
Type?[] argumentTypes;
if (parameters.Length == 0)
{
argumentTypes = Type.EmptyTypes;
argumentTypes = [];
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

namespace System
{
internal partial class DefaultBinder : Binder
internal class DefaultBinder : Binder
{
internal static readonly DefaultBinder Instance = new DefaultBinder();

// This method is passed a set of methods and must choose the best
// fit. The methods all have the same number of arguments and the object
// array args. On exit, this method will choice the best fit method
Expand Down Expand Up @@ -204,7 +206,7 @@ public sealed override MethodBase BindToMethod(
continue;

// a default value is available
if (defaultValueBinding && args[index] == Type.Missing)
if (defaultValueBinding && args[index] == Missing.Value)
continue;

// the argument was null, so it matches with everything
Expand Down Expand Up @@ -876,7 +878,7 @@ private static int FindMostSpecific(ReadOnlySpan<ParameterInfo> p1, int[] paramO

for (int i = 0; i < types.Length; i++)
{
if (args != null && args[i] == Type.Missing)
if (args != null && args[i] == Missing.Value)
continue;

Type c1, c2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading;

namespace System.Globalization
{
Expand Down Expand Up @@ -443,12 +444,13 @@ internal sealed partial class CultureData
if (tempHashTable == null)
{
// No table yet, make a new one
tempHashTable = new Dictionary<string, CultureData>();
var newTable = new Dictionary<string, CultureData>();
tempHashTable = Interlocked.CompareExchange(ref s_cachedRegions, newTable, null) ?? newTable;
}
else
{
// Check the hash table
lock (s_lock)
lock (tempHashTable)
{
tempHashTable.TryGetValue(hashName, out retVal);
}
Expand Down Expand Up @@ -481,14 +483,10 @@ internal sealed partial class CultureData
if (retVal != null && !retVal.IsNeutralCulture)
{
// first add it to the cache
lock (s_lock)
lock (tempHashTable)
{
tempHashTable[hashName] = retVal;
}

// Copy the hashtable to the corresponding member variables. This will potentially overwrite
// new tables simultaneously created by a new thread, but maximizes thread safety.
s_cachedRegions = tempHashTable;
}
else
{
Expand Down Expand Up @@ -658,7 +656,6 @@ private static CultureData CreateCultureWithInvariantData()

// Cache of cultures we've already looked up
private static volatile Dictionary<string, CultureData>? s_cachedCultures;
private static readonly object s_lock = new object();

internal static CultureData? GetCultureData(string? cultureName, bool useUserOverride)
{
Expand All @@ -683,14 +680,15 @@ private static CultureData CreateCultureWithInvariantData()
if (tempHashTable == null)
{
// No table yet, make a new one
tempHashTable = new Dictionary<string, CultureData>();
var newTable = new Dictionary<string, CultureData>();
tempHashTable = Interlocked.CompareExchange(ref s_cachedCultures, newTable, null) ?? newTable;
}
else
{
// Check the hash table
bool ret;
CultureData? retVal;
lock (s_lock)
lock (tempHashTable)
{
ret = tempHashTable.TryGetValue(hashName, out retVal);
}
Expand All @@ -707,15 +705,11 @@ private static CultureData CreateCultureWithInvariantData()
}

// Found one, add it to the cache
lock (s_lock)
lock (tempHashTable)
{
tempHashTable[hashName] = culture;
}

// Copy the hashtable to the corresponding member variables. This will potentially overwrite
// new tables simultaneously created by a new thread, but maximizes thread safety.
s_cachedCultures = tempHashTable;

return culture;
}

Expand Down
Loading