Skip to content

Commit

Permalink
One more code simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
andy31415 committed Dec 18, 2024
1 parent 970908f commit 4190eac
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions src/data-model-providers/codegen/CodegenDataModelProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -844,20 +844,8 @@ void CodegenDataModelProvider::InitDataModelForTesting()
std::unique_ptr<DataModel::ElementIterator<DataModel::DeviceTypeEntry>>
CodegenDataModelProvider::GetDeviceTypes(EndpointId endpointId)
{
// Use the `Index` version even though `emberAfDeviceTypeListFromEndpoint` would work because
// index finding is cached in TryFindEndpointIndex and this avoids an extra `emberAfIndexFromEndpoint`
// during `Next` loops. This avoids O(n^2) on number of indexes when iterating over all device types.
//
// Not actually needed for `First`, however this makes First and Next consistent.
std::optional<unsigned> endpoint_index = TryFindEndpointIndex(endpointId);
if (!endpoint_index.has_value())
{
// do not use the NULL iterator to save flash on what classs are instantiated
return std::make_unique<DeviceTypeEntryIterator>(Span<EmberAfDeviceType>());
}

CHIP_ERROR err = CHIP_NO_ERROR;
return std::make_unique<DeviceTypeEntryIterator>(emberAfDeviceTypeListFromEndpointIndex(*endpoint_index, err));
return std::make_unique<DeviceTypeEntryIterator>(emberAfDeviceTypeListFromEndpoint(endpointId, err));
}

std::unique_ptr<DataModel::ElementIterator<DataModel::Provider::SemanticTag>>
Expand Down

0 comments on commit 4190eac

Please sign in to comment.