Weaver ILPostProcessorAssemblyResolver: use GetFileNameWithoutExtension

This commit is contained in:
mischa 2023-06-20 11:34:42 +08:00 committed by mischa
parent 8cb58d73e8
commit c687bdd24a

View File

@ -124,20 +124,18 @@ public AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters p
// find assemblyname in assembly's references
string FindFile(string name)
{
// this is called thousands(!) of times.
// constructing strings only once saves ~0.1ms per call for mscorlib.
string dllName = name + ".dll";
string exeName = name + ".exe";
// perhaps the type comes from a dll or exe
// perhaps the type comes from a .dll or .exe
// check both in one call without Linq instead of iterating twice like originally
foreach (string r in assemblyReferences)
{
string fileName = Path.GetFileName(r);
if (fileName == dllName || fileName == exeName)
if (Path.GetFileNameWithoutExtension(r) == name)
return r;
}
// this is called thousands(!) of times.
// constructing strings only once saves ~0.1ms per call for mscorlib.
string dllName = name + ".dll";
// Unfortunately the current ICompiledAssembly API only provides direct references.
// It is very much possible that a postprocessor ends up investigating a type in a directly
// referenced assembly, that contains a field that is not in a directly referenced assembly.