From 9ac41c21ca2e18fd4472d4bdaf081ebcaad12857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Mon, 3 Jan 2022 20:01:01 +0100 Subject: [PATCH] feat: do not use linq in FindPacketInfo --- .../Packets/PacketTypesRepository.cs | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/Core/NosSmooth.Packets/Packets/PacketTypesRepository.cs b/Core/NosSmooth.Packets/Packets/PacketTypesRepository.cs index 9e62940..9fadb39 100644 --- a/Core/NosSmooth.Packets/Packets/PacketTypesRepository.cs +++ b/Core/NosSmooth.Packets/Packets/PacketTypesRepository.cs @@ -103,16 +103,28 @@ public class PacketTypesRepository : IPacketTypesRepository return _headerToPacket[preferredSource][header]; } - var foundPackets = _headerToPacket.Values - .Where(x => x.ContainsKey(header)) - .Select(x => x[header]).ToArray(); + PacketInfo? info = null; + foreach (var dict in _headerToPacket.Values) + { + if (dict.ContainsKey(header)) + { + if (info is null) + { + info = dict[header]; + } + else + { + return new AmbiguousHeaderError(header, null, new PacketInfo[] { dict[header], info }); + } + } + } - return foundPackets.Length switch + if (info is null) { - 1 => foundPackets[0], - 0 => new PacketConverterNotFoundError(header), - _ => new AmbiguousHeaderError(header, null, foundPackets) - }; + return new PacketConverterNotFoundError(header); + } + + return info; } /// -- 2.49.0