File tree 1 file changed +8
-0
lines changed
src/app/codegen-data-model-provider
1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -746,6 +746,11 @@ ConcreteCommandPath CodegenDataModelProvider::NextGeneratedCommand(const Concret
746
746
747
747
std::optional<DataModel::DeviceTypeEntry> CodegenDataModelProvider::FirstDeviceType (EndpointId endpoint)
748
748
{
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.
749
754
std::optional<unsigned > endpoint_index = TryFindEndpointIndex (endpoint);
750
755
if (!endpoint_index.has_value ())
751
756
{
@@ -768,6 +773,9 @@ std::optional<DataModel::DeviceTypeEntry> CodegenDataModelProvider::FirstDeviceT
768
773
std::optional<DataModel::DeviceTypeEntry> CodegenDataModelProvider::NextDeviceType (EndpointId endpoint,
769
774
const DataModel::DeviceTypeEntry & previous)
770
775
{
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.
771
779
std::optional<unsigned > endpoint_index = TryFindEndpointIndex (endpoint);
772
780
if (!endpoint_index.has_value ())
773
781
{
You can’t perform that action at this time.
0 commit comments