Skip to content

Commit d203154

Browse files
committed
more comments
1 parent db682f2 commit d203154

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/app/codegen-data-model-provider/CodegenDataModelProvider.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,11 @@ ConcreteCommandPath CodegenDataModelProvider::NextGeneratedCommand(const Concret
746746

747747
std::optional<DataModel::DeviceTypeEntry> CodegenDataModelProvider::FirstDeviceType(EndpointId endpoint)
748748
{
749+
// Use the `Index` version even though `emberAfDeviceTypeListFromEndpoint` would work because
750+
// index finding is cached in TryFindEndpointIndex and this avoids an extra `emberAfIndexFromEndpoint`
751+
// during `Next` loops. This avoids O(n^2) on number of indexes when iterating over all device types.
752+
//
753+
// Not actually needed for `First`, however this makes First and Next consistent.
749754
std::optional<unsigned> endpoint_index = TryFindEndpointIndex(endpoint);
750755
if (!endpoint_index.has_value())
751756
{
@@ -768,6 +773,9 @@ std::optional<DataModel::DeviceTypeEntry> CodegenDataModelProvider::FirstDeviceT
768773
std::optional<DataModel::DeviceTypeEntry> CodegenDataModelProvider::NextDeviceType(EndpointId endpoint,
769774
const DataModel::DeviceTypeEntry & previous)
770775
{
776+
// Use the `Index` version even though `emberAfDeviceTypeListFromEndpoint` would work because
777+
// index finding is cached in TryFindEndpointIndex and this avoids an extra `emberAfIndexFromEndpoint`
778+
// during `Next` loops. This avoids O(n^2) on number of indexes when iterating over all device types.
771779
std::optional<unsigned> endpoint_index = TryFindEndpointIndex(endpoint);
772780
if (!endpoint_index.has_value())
773781
{

0 commit comments

Comments
 (0)