Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AVRO-3893: Avoid unnecessary lambda capture on each invocation of 'ObjectCreator.FindType' #2565

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 7 additions & 7 deletions lang/csharp/src/apache/main/Specific/ObjectCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,30 +81,30 @@ public ObjectCreator()
/// </exception>
private Type FindType(string name)
{
return typeCacheByName.GetOrAdd(name, (_) =>
return typeCacheByName.GetOrAdd(name, (typeName) =>
{
Type type = null;

if (TryGetIListItemTypeName(name, out var itemTypeName))
if (TryGetIListItemTypeName(typeName, out var itemTypeName))
{
return GenericIListType.MakeGenericType(FindType(itemTypeName));
}

if (TryGetNullableItemTypeName(name, out itemTypeName))
if (TryGetNullableItemTypeName(typeName, out itemTypeName))
{
return GenericNullableType.MakeGenericType(FindType(itemTypeName));
}

// if entry assembly different from current assembly, try entry assembly first
if (diffAssembly)
{
type = entryAssembly.GetType(name);
type = entryAssembly.GetType(typeName);
}

// try current assembly and mscorlib
if (type == null)
{
type = Type.GetType(name);
type = Type.GetType(typeName);
}

// type is still not found, need to loop through all loaded assemblies
Expand All @@ -119,7 +119,7 @@ private Type FindType(string name)
// Change the search to look for Types by both NAME and FULLNAME
foreach (Type t in assembly.GetTypes())
{
if (name == t.Name || name == t.FullName || CodeGenUtil.Instance.UnMangle(name) == t.FullName)
if (typeName == t.Name || typeName == t.FullName || CodeGenUtil.Instance.UnMangle(typeName) == t.FullName)
{
type = t;
break;
Expand All @@ -134,7 +134,7 @@ private Type FindType(string name)
}

return type
?? throw new AvroException($"Unable to find type '{name}' in all loaded " +
?? throw new AvroException($"Unable to find type '{typeName}' in all loaded " +
$"assemblies");
});
}
Expand Down