@@ -726,8 +726,7 @@ const EmberAfCluster * emberAfFindClusterInType(const EmberAfEndpointType * endp
726
726
{
727
727
const EmberAfCluster * cluster = &(endpointType->cluster [i]);
728
728
729
- if ((mask == 0 || (mask == CLUSTER_MASK_CLIENT && emberAfClusterIsClient (cluster)) ||
730
- (mask == CLUSTER_MASK_SERVER && emberAfClusterIsServer (cluster))))
729
+ if (mask == 0 || ((cluster->mask & mask) != 0 ))
731
730
{
732
731
if (cluster->clusterId == clusterId)
733
732
{
@@ -1038,20 +1037,10 @@ uint8_t emberAfClusterCountByIndex(uint16_t endpointIndex, bool server)
1038
1037
1039
1038
uint8_t emberAfClusterCountForEndpointType (const EmberAfEndpointType * type, bool server)
1040
1039
{
1041
- uint8_t c = 0 ;
1042
- for (uint8_t i = 0 ; i < type->clusterCount ; i++)
1043
- {
1044
- auto * cluster = &(type->cluster [i]);
1045
- if (server && emberAfClusterIsServer (cluster))
1046
- {
1047
- c++;
1048
- }
1049
- if ((!server) && emberAfClusterIsClient (cluster))
1050
- {
1051
- c++;
1052
- }
1053
- }
1054
- return c;
1040
+ const EmberAfClusterMask cluster_mask = server ? CLUSTER_MASK_SERVER : CLUSTER_MASK_CLIENT;
1041
+
1042
+ return static_cast <uint8_t >(std::count_if (type->cluster , type->cluster + type->clusterCount ,
1043
+ [=](const EmberAfCluster & cluster) { return (cluster.mask & cluster_mask) != 0 ; }));
1055
1044
}
1056
1045
1057
1046
uint8_t emberAfGetClusterCountForEndpoint (EndpointId endpoint)
@@ -1121,28 +1110,31 @@ CHIP_ERROR SetTagList(EndpointId endpoint, Span<const Clusters::Descriptor::Stru
1121
1110
const EmberAfCluster * emberAfGetNthCluster (EndpointId endpoint, uint8_t n, bool server)
1122
1111
{
1123
1112
uint16_t index = emberAfIndexFromEndpoint (endpoint);
1124
- EmberAfDefinedEndpoint * de;
1125
- uint8_t i, c = 0 ;
1126
- const EmberAfCluster * cluster;
1127
-
1128
1113
if (index == kEmberInvalidEndpointIndex )
1129
1114
{
1130
1115
return nullptr ;
1131
1116
}
1132
- de = &(emAfEndpoints[index ]);
1133
1117
1134
- for (i = 0 ; i < de->endpointType ->clusterCount ; i++)
1118
+ const EmberAfEndpointType * endpointType = emAfEndpoints[index ].endpointType ;
1119
+ const EmberAfClusterMask cluster_mask = server ? CLUSTER_MASK_SERVER : CLUSTER_MASK_CLIENT;
1120
+ const uint8_t clusterCount = endpointType->clusterCount ;
1121
+
1122
+ uint8_t c = 0 ;
1123
+ for (uint8_t i = 0 ; i < clusterCount; i++)
1135
1124
{
1136
- cluster = &(de-> endpointType ->cluster [i]);
1125
+ const EmberAfCluster * cluster = &(endpointType->cluster [i]);
1137
1126
1138
- if ((server && emberAfClusterIsServer (cluster)) || ((!server) && emberAfClusterIsClient (cluster)) )
1127
+ if ((cluster-> mask & cluster_mask) == 0 )
1139
1128
{
1140
- if (c == n)
1141
- {
1142
- return cluster;
1143
- }
1144
- c++;
1129
+ continue ;
1145
1130
}
1131
+
1132
+ if (c == n)
1133
+ {
1134
+ return cluster;
1135
+ }
1136
+
1137
+ c++;
1146
1138
}
1147
1139
return nullptr ;
1148
1140
}
0 commit comments