Skip to content

Commit 1ef74e4

Browse files
committed
Modify from comment
1 parent 64948d4 commit 1ef74e4

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/controller/AbstractDnssdDiscoveryController.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,32 @@
2222
#include <lib/core/CHIPEncoding.h>
2323
#include <lib/support/logging/CHIPLogging.h>
2424

25+
#include <bitset>
26+
2527
namespace chip {
2628
namespace Controller {
2729

28-
bool AddressListsSameExceptOrder(const size_t sourceNumIPs, const size_t destinationNumIPs,
29-
const Inet::IPAddress source[Dnssd::CommissionNodeData::kMaxIPAddresses],
30-
const Inet::IPAddress destination[Dnssd::CommissionNodeData::kMaxIPAddresses])
30+
static bool SameExceptOrder(const chip::Span<const Inet::IPAddress> &source, const chip::Span<const Inet::IPAddress> &destination)
3131
{
32-
size_t sameIpAddress = 0;
33-
bool addressUsed[chip::Dnssd::CommonResolutionData::kMaxIPAddresses] = { false };
34-
if (sourceNumIPs != destinationNumIPs)
32+
std::bitset<chip::Dnssd::CommonResolutionData::kMaxIPAddresses> addressUsed;
33+
if (source.size() != destination.size())
3534
{
3635
return false;
3736
}
3837

39-
for (size_t s = 0; s < sourceNumIPs; s++)
38+
for (size_t s = 0; s < source.size(); s++)
4039
{
41-
for (size_t d = 0; d < destinationNumIPs; d++)
40+
for (size_t d = 0; d < destination.size(); d++)
4241
{
4342
if (!addressUsed[d] && source[s] == destination[d])
4443
{
4544
// Change the user flag so that the compared target is no longer used
46-
addressUsed[d] = true;
47-
sameIpAddress++;
45+
addressUsed.set(d, true);
4846
break;
4947
}
5048
}
5149
}
52-
return sameIpAddress == destinationNumIPs;
50+
return addressUsed.count() == destination.size();
5351
}
5452

5553
void AbstractDnssdDiscoveryController::OnNodeDiscovered(const chip::Dnssd::DiscoveredNodeData & discNodeData)
@@ -65,8 +63,10 @@ void AbstractDnssdDiscoveryController::OnNodeDiscovered(const chip::Dnssd::Disco
6563
{
6664
continue;
6765
}
66+
chip::Span<const Inet::IPAddress> discoveredNodeIPAddressSpan(&discoveredNode.ipAddress[0], discoveredNode.numIPs);
67+
chip::Span<const Inet::IPAddress> nodeDataIPAddressSpan(&nodeData.ipAddress[0], nodeData.numIPs);
6868
if (strcmp(discoveredNode.hostName, nodeData.hostName) == 0 && discoveredNode.port == nodeData.port &&
69-
AddressListsSameExceptOrder(discoveredNode.numIPs, nodeData.numIPs, discoveredNode.ipAddress, nodeData.ipAddress))
69+
SameExceptOrder(discoveredNodeIPAddressSpan, nodeDataIPAddressSpan))
7070
{
7171
discoveredNode = nodeData;
7272
if (mDeviceDiscoveryDelegate != nullptr)

0 commit comments

Comments
 (0)