mirror of
https://github.com/oliverbooth/TcpDotNet
synced 2024-11-09 23:05:41 +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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
|
ConstructorInfo? constructor = GetConstructor(packetType);
|
||||||
ConstructorInfo? constructor =
|
|
||||||
packetType.GetConstructors(bindingFlags).FirstOrDefault(c => c.GetParameters().Length == 0);
|
|
||||||
|
|
||||||
if (constructor is null)
|
if (constructor is null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@ -259,6 +256,24 @@ public abstract class ClientNode : Node
|
|||||||
return WaitForPacketAsync<TPacket>(completionSource, cancellationToken);
|
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,
|
private async Task<TPacket> WaitForPacketAsync<TPacket>(TaskCompletionSource<Packet> completionSource,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
where TPacket : Packet
|
where TPacket : Packet
|
||||||
|
Loading…
Reference in New Issue
Block a user