From 1ef74e4a5bbb4da9ffe7998b770140098c2c5d38 Mon Sep 17 00:00:00 2001 From: Joonhaeng Heo Date: Mon, 27 May 2024 08:59:11 +0900 Subject: [PATCH] Modify from comment --- .../AbstractDnssdDiscoveryController.cpp | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/controller/AbstractDnssdDiscoveryController.cpp b/src/controller/AbstractDnssdDiscoveryController.cpp index 44f59b68f6e6a2..6d89ff00491ce9 100644 --- a/src/controller/AbstractDnssdDiscoveryController.cpp +++ b/src/controller/AbstractDnssdDiscoveryController.cpp @@ -22,34 +22,32 @@ #include #include +#include + namespace chip { namespace Controller { -bool AddressListsSameExceptOrder(const size_t sourceNumIPs, const size_t destinationNumIPs, - const Inet::IPAddress source[Dnssd::CommissionNodeData::kMaxIPAddresses], - const Inet::IPAddress destination[Dnssd::CommissionNodeData::kMaxIPAddresses]) +static bool SameExceptOrder(const chip::Span &source, const chip::Span &destination) { - size_t sameIpAddress = 0; - bool addressUsed[chip::Dnssd::CommonResolutionData::kMaxIPAddresses] = { false }; - if (sourceNumIPs != destinationNumIPs) + std::bitset addressUsed; + if (source.size() != destination.size()) { return false; } - for (size_t s = 0; s < sourceNumIPs; s++) + for (size_t s = 0; s < source.size(); s++) { - for (size_t d = 0; d < destinationNumIPs; d++) + for (size_t d = 0; d < destination.size(); d++) { if (!addressUsed[d] && source[s] == destination[d]) { // Change the user flag so that the compared target is no longer used - addressUsed[d] = true; - sameIpAddress++; + addressUsed.set(d, true); break; } } } - return sameIpAddress == destinationNumIPs; + return addressUsed.count() == destination.size(); } void AbstractDnssdDiscoveryController::OnNodeDiscovered(const chip::Dnssd::DiscoveredNodeData & discNodeData) @@ -65,8 +63,10 @@ void AbstractDnssdDiscoveryController::OnNodeDiscovered(const chip::Dnssd::Disco { continue; } + chip::Span discoveredNodeIPAddressSpan(&discoveredNode.ipAddress[0], discoveredNode.numIPs); + chip::Span nodeDataIPAddressSpan(&nodeData.ipAddress[0], nodeData.numIPs); if (strcmp(discoveredNode.hostName, nodeData.hostName) == 0 && discoveredNode.port == nodeData.port && - AddressListsSameExceptOrder(discoveredNode.numIPs, nodeData.numIPs, discoveredNode.ipAddress, nodeData.ipAddress)) + SameExceptOrder(discoveredNodeIPAddressSpan, nodeDataIPAddressSpan)) { discoveredNode = nodeData; if (mDeviceDiscoveryDelegate != nullptr)