diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/main_core/update.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/main_core/update.hpp index f73cd359d..c2ec21a72 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/main_core/update.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/main_core/update.hpp @@ -235,18 +235,13 @@ UpdateCompProperties check_component_independence(ConstDataset const& update_dat template using ComponentFlags = std::array; template -ComponentFlags -is_update_independent(ConstDataset const& update_data, - std::map> const& relevant_component_count_map) { +ComponentFlags is_update_independent(ConstDataset const& update_data, + std::span relevant_component_count) { ComponentFlags result{}; size_t idx{}; utils::run_functor_with_all_types_return_void( - [&result, &relevant_component_count_map, &update_data, &idx]() { - Idx n_component{}; - auto it = relevant_component_count_map.find(CompType::name); - if (it != relevant_component_count_map.end()) { - n_component = it->second; - } + [&result, &relevant_component_count, &update_data, &idx]() { + Idx n_component = relevant_component_count[idx]; result[idx] = check_component_independence(update_data, n_component).is_independent(); ++idx; }); diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp index 45214433f..72c13dcd1 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp @@ -186,6 +186,18 @@ class MainModelImpl, ComponentLis return result; } + // helper function to get the number of components per type + std::array get_n_components_per_type() const { + std::array result{}; + size_t idx{}; + main_core::utils::run_functor_with_all_types_return_void( + [&result, this, &idx]() { + result[idx] = this->component_count(); + ++idx; + }); + return result; + } + // helper function to add vectors of components template void add_component(std::vector const& components) { add_component(components.begin(), components.end()); @@ -580,10 +592,9 @@ class MainModelImpl, ComponentLis // cache component update order where possible. // the order for a cacheable (independent) component by definition is the same across all scenarios - // TODO: (figueroa1395): don't use string lookup, it is slow - std::map> const relevant_component_count_map = all_component_count(); + auto const relevant_component_count = get_n_components_per_type(); auto const is_independent = - main_core::is_update_independent(update_data, relevant_component_count_map); + main_core::is_update_independent(update_data, relevant_component_count); all_scenarios_sequence = get_sequence_idx_map(update_data, 0, is_independent); return [&base_model, &exceptions, &infos, &calculation_fn, &result_data, &update_data,