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

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Runtime.General;

//==================================================================================================================
// Dependency note:
Expand Down Expand Up @@ -110,13 +111,15 @@ public virtual E GetParent(E e)
//
private IEnumerable<CustomAttributeData> GetMatchingCustomAttributesIterator(E element, Func<Type, bool> passesFilter, bool inherit)
{
LowLevelList<CustomAttributeData> immediateResults = new LowLevelList<CustomAttributeData>();
ListBuilder<CustomAttributeData> immediateResults = default;
foreach (CustomAttributeData cad in GetDeclaredCustomAttributes(element))
{
if (passesFilter(cad.AttributeType))
{
yield return cad;
immediateResults.Add(cad);

if (inherit)
immediateResults.Add(cad);
}
}
if (inherit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ public override int GetHashCode()
public IntPtr InstantiationArgument;
}

private static uint s_genericFunctionPointerNextIndex;
private const uint c_genericDictionaryChunkSize = 1024;
private static LowLevelList<IntPtr> s_genericFunctionPointerCollection = new LowLevelList<IntPtr>();
private static LowLevelDictionary<GenericMethodDescriptorInfo, uint> s_genericFunctionPointerDictionary = new LowLevelDictionary<GenericMethodDescriptorInfo, uint>();
private static LowLevelDictionary<GenericMethodDescriptorInfo, IntPtr> s_genericFunctionPointerDictionary = new LowLevelDictionary<GenericMethodDescriptorInfo, IntPtr>();

public static unsafe IntPtr GetGenericMethodFunctionPointer(IntPtr canonFunctionPointer, IntPtr instantiationArgument)
{
Expand All @@ -69,38 +66,17 @@ public static unsafe IntPtr GetGenericMethodFunctionPointer(IntPtr canonFunction
InstantiationArgument = instantiationArgument
};

uint index = 0;
if (!s_genericFunctionPointerDictionary.TryGetValue(key, out index))
if (!s_genericFunctionPointerDictionary.TryGetValue(key, out IntPtr descriptor))
{
// Capture new index value
index = s_genericFunctionPointerNextIndex;
descriptor = (IntPtr)NativeMemory.Alloc((uint)sizeof(GenericMethodDescriptor));

int newChunkIndex = (int)(index / c_genericDictionaryChunkSize);
uint newSubChunkIndex = index % c_genericDictionaryChunkSize;

// Generate new chunk if existing chunks are insufficient
if (s_genericFunctionPointerCollection.Count <= newChunkIndex)
{
Debug.Assert(newSubChunkIndex == 0);

// New generic descriptors are allocated on the native heap and not tracked in the GC.
IntPtr pNewMem = (IntPtr)NativeMemory.Alloc(c_genericDictionaryChunkSize, (nuint)sizeof(GenericMethodDescriptor));
s_genericFunctionPointerCollection.Add(pNewMem);
}

((GenericMethodDescriptor*)s_genericFunctionPointerCollection[newChunkIndex])[newSubChunkIndex] =
*(GenericMethodDescriptor*)descriptor =
new GenericMethodDescriptor(canonFunctionPointer, instantiationArgument);

s_genericFunctionPointerDictionary.LookupOrAdd(key, index);

// Now that we can no longer have failed, update the next index.
s_genericFunctionPointerNextIndex++;
s_genericFunctionPointerDictionary.LookupOrAdd(key, descriptor);
}

// Lookup within list
int chunkIndex = (int)(index / c_genericDictionaryChunkSize);
uint subChunkIndex = index % c_genericDictionaryChunkSize;
GenericMethodDescriptor* genericFunctionPointer = &((GenericMethodDescriptor*)s_genericFunctionPointerCollection[chunkIndex])[subChunkIndex];
GenericMethodDescriptor* genericFunctionPointer = (GenericMethodDescriptor*)descriptor;

Debug.Assert(canonFunctionPointer == genericFunctionPointer->MethodFunctionPointer);
Debug.Assert(instantiationArgument == genericFunctionPointer->InstantiationArgument);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,6 @@
<Compile Include="$(CompilerCommonPath)\TypeSystem\Common\TypeHashingAlgorithms.cs">
<Link>Utilities\TypeHashingAlgorithms.cs</Link>
</Compile>
<Compile Include="$(AotCommonPath)\System\Collections\Generic\LowLevelList.cs">
<Link>System\Collections\Generic\LowLevelList.cs</Link>
</Compile>
<Compile Include="$(AotCommonPath)\System\Collections\Generic\LowLevelDictionary.cs">
<Link>System\Collections\Generic\LowLevelDictionary.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal NamespaceChain(MetadataReader reader, NamespaceDefinitionHandle innerMo
NamespaceDefinition currentNamespaceDefinition = innerMostNamespaceHandle.GetNamespaceDefinition(reader);
ConstantStringValueHandle currentNameHandle = currentNamespaceDefinition.Name;
Handle currentNamespaceHandle;
LowLevelList<string> names = new LowLevelList<string>();
ListBuilder<string> names = default;
for (; ; )
{
string name = currentNameHandle.GetStringOrNull(reader);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\..\System.Private.CoreLib\src\System.Private.CoreLib.csproj" />
<ProjectReference Include="..\..\System.Private.TypeLoader\src\System.Private.TypeLoader.csproj" />
Expand Down Expand Up @@ -56,9 +56,6 @@
<Link>System\NotImplemented.cs</Link>
</Compile>
<Compile Include="$(LibrariesProjectRoot)\System.Private.CoreLib\src\System\SR.cs" />
<Compile Include="$(AotCommonPath)\System\Collections\Generic\LowLevelList.cs">
<Link>System\Collections\Generic\LowLevelList.cs</Link>
</Compile>
<Compile Include="$(AotCommonPath)\System\Collections\Generic\LowLevelDictionary.cs">
<Link>System\Collections\Generic\LowLevelDictionary.cs</Link>
</Compile>
Expand All @@ -74,8 +71,5 @@
<Compile Include="$(LibrariesProjectRoot)\System.Private.CoreLib\src\System\Collections\HashHelpers.cs">
<Link>System\Collections\HashHelpers.cs</Link>
</Compile>
<Compile Include="$(AotCommonPath)\System\Collections\Generic\Empty.cs">
<Link>System\Collections\Generic\Empty.cs</Link>
</Compile>
</ItemGroup>
</Project>
Loading
Loading