diff options
author | George L. Albany <Megacake1234@gmail.com> | 2023-10-17 20:58:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-17 20:58:14 +0200 |
commit | b0a1dc5adef58671c1f1b8a73c7a8b9b26bb84ac (patch) | |
tree | 0b541649c2593a8aa649dd47a645137442b0d305 /src/openvic-simulation/types/IdentifierRegistry.hpp | |
parent | d4f3231d53da69d98312523fbd9ffee31f3aeaf1 (diff) | |
parent | ed15f46d03f50b93b4cf2bb58da7217e3150f86d (diff) |
Merge pull request #58 from OpenVicProject/optimize/some-registry
Diffstat (limited to 'src/openvic-simulation/types/IdentifierRegistry.hpp')
-rw-r--r-- | src/openvic-simulation/types/IdentifierRegistry.hpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/openvic-simulation/types/IdentifierRegistry.hpp b/src/openvic-simulation/types/IdentifierRegistry.hpp index 1a03e75..f8ece3e 100644 --- a/src/openvic-simulation/types/IdentifierRegistry.hpp +++ b/src/openvic-simulation/types/IdentifierRegistry.hpp @@ -135,9 +135,14 @@ namespace OpenVic { return false; } const std::string_view new_identifier = GetIdentifier(GetPointer(item)); - value_type const* old_item = get_item_by_identifier(new_identifier); - if (old_item != nullptr) { - return duplicate_callback(name, new_identifier); + if (duplicate_callback && + duplicate_callback.target<bool(std::string_view, std::string_view)>() == duplicate_ignore_callback) { + if (has_identifier(new_identifier)) return true; + } else { + value_type const* old_item = get_item_by_identifier(new_identifier); + if (old_item != nullptr) { + return duplicate_callback(name, new_identifier); + } } identifier_index_map.emplace(new_identifier, items.size()); items.push_back(std::move(item)); @@ -217,18 +222,17 @@ GETTERS #undef GETTERS bool has_identifier(std::string_view identifier) const { - return get_item_by_identifier(identifier) != nullptr; + return identifier_index_map.contains(identifier); } bool has_index(size_t index) const { - return get_item_by_index(index) != nullptr; + return index < size(); } REF_GETTERS(items) std::vector<std::string_view> get_item_identifiers() const { - std::vector<std::string_view> identifiers; - identifiers.reserve(items.size()); + std::vector<std::string_view> identifiers(items.size()); for (typename decltype(identifier_index_map)::value_type const& entry : identifier_index_map) { identifiers.push_back(entry.first); } @@ -241,7 +245,7 @@ GETTERS bool ret = expect_item_dictionary([&map](value_type const& key, ast::NodeCPtr value) -> bool { fixed_point_t val; const bool ret = NodeTools::expect_fixed_point(NodeTools::assign_variable_callback(val))(value); - map.emplace(&key, val); + map.emplace(&key, std::move(val)); return ret; })(node); ret &= callback(std::move(map)); |