~ruther/NosSmooth

9ac41c21ca2e18fd4472d4bdaf081ebcaad12857 — František Boháček 3 years ago 72493df
feat: do not use linq in FindPacketInfo
1 files changed, 20 insertions(+), 8 deletions(-)

M Core/NosSmooth.Packets/Packets/PacketTypesRepository.cs
M Core/NosSmooth.Packets/Packets/PacketTypesRepository.cs => Core/NosSmooth.Packets/Packets/PacketTypesRepository.cs +20 -8
@@ 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;
    }

    /// <summary>