Skip to content
Merged
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 @@ -1252,20 +1252,30 @@ private RuntimePropertyInfo[] PopulateProperties(Filter filter)
Dictionary<string, List<RuntimePropertyInfo>>? csPropertyInfos = filter.CaseSensitive() ? null :
new Dictionary<string, List<RuntimePropertyInfo>>();

// All elements automatically initialized to false.
bool[] usedSlots = new bool[RuntimeTypeHandle.GetNumVirtuals(declaringType)];
// All elements initialized to false.
int numVirtuals = RuntimeTypeHandle.GetNumVirtuals(declaringType);
Span<bool> usedSlots = stackalloc bool[0];
if (numVirtuals <= 128) // arbitrary stack limit
{
usedSlots = stackalloc bool[numVirtuals];
usedSlots.Clear();
}
else
{
usedSlots = new bool[numVirtuals];
}

// Populate associates off of the class hierarchy
do
{
PopulateProperties(filter, declaringType, csPropertyInfos, usedSlots, ref list);
PopulateProperties(filter, declaringType, csPropertyInfos, usedSlots, isInterface: false, ref list);
declaringType = RuntimeTypeHandle.GetBaseType(declaringType);
} while (declaringType != null);
}
else
{
// Populate associates for this interface
PopulateProperties(filter, declaringType, null, null, ref list);
PopulateProperties(filter, declaringType, null, default, isInterface: true, ref list);
}

return list.ToArray();
Expand All @@ -1275,7 +1285,8 @@ private void PopulateProperties(
Filter filter,
RuntimeType declaringType,
Dictionary<string, List<RuntimePropertyInfo>>? csPropertyInfos,
bool[]? usedSlots,
Span<bool> usedSlots,
bool isInterface,
ref ListBuilder<RuntimePropertyInfo> list)
{
int tkDeclaringType = RuntimeTypeHandle.GetToken(declaringType);
Expand All @@ -1290,8 +1301,8 @@ private void PopulateProperties(

int numVirtuals = RuntimeTypeHandle.GetNumVirtuals(declaringType);

Debug.Assert((declaringType.IsInterface && usedSlots == null && csPropertyInfos == null) ||
(!declaringType.IsInterface && usedSlots != null && usedSlots.Length >= numVirtuals));
Debug.Assert((declaringType.IsInterface && isInterface && csPropertyInfos == null) ||
(!declaringType.IsInterface && !isInterface && usedSlots.Length >= numVirtuals));

for (int i = 0; i < tkProperties.Length; i++)
{
Expand All @@ -1313,7 +1324,7 @@ private void PopulateProperties(
tkProperty, declaringType, m_runtimeTypeCache, out bool isPrivate);

// If this is a class, not an interface
if (usedSlots != null)
if (!isInterface)
{
#region Remove Privates
if (declaringType != ReflectedType && isPrivate)
Expand Down