mirror of
https://github.com/oliverbooth/TcpDotNet
synced 2024-11-23 00:28:48 +00:00
perf: remove LINQ in ctor lookup
This commit is contained in:
parent
45a0b3898a
commit
50a73d21eb
@ -140,10 +140,7 @@ public abstract class ClientNode : Node
|
||||
return null;
|
||||
}
|
||||
|
||||
const BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
|
||||
ConstructorInfo? constructor =
|
||||
packetType.GetConstructors(bindingFlags).FirstOrDefault(c => c.GetParameters().Length == 0);
|
||||
|
||||
ConstructorInfo? constructor = GetConstructor(packetType);
|
||||
if (constructor is null)
|
||||
return null;
|
||||
|
||||
@ -259,6 +256,24 @@ public abstract class ClientNode : Node
|
||||
return WaitForPacketAsync<TPacket>(completionSource, cancellationToken);
|
||||
}
|
||||
|
||||
private static ConstructorInfo? GetConstructor(Type packetType)
|
||||
{
|
||||
const BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
|
||||
ConstructorInfo[] constructors = packetType.GetConstructors(bindingFlags);
|
||||
ConstructorInfo? constructor = null;
|
||||
for (var index = 0; index < constructors.Length; index++)
|
||||
{
|
||||
ConstructorInfo current = constructors[index];
|
||||
if (current.GetParameters().Length == 0)
|
||||
{
|
||||
constructor = current;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return constructor;
|
||||
}
|
||||
|
||||
private async Task<TPacket> WaitForPacketAsync<TPacket>(TaskCompletionSource<Packet> completionSource,
|
||||
CancellationToken cancellationToken = default)
|
||||
where TPacket : Packet
|
||||
|
Loading…
Reference in New Issue
Block a user