From d236dcf30c001e540377184565f4d173ed56f76e Mon Sep 17 00:00:00 2001 From: Spartan322 Date: Sat, 6 Jul 2024 10:40:57 -0400 Subject: Optimize some string interning cases --- src/openvic-simulation/military/Wargoal.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/openvic-simulation/military/Wargoal.cpp') diff --git a/src/openvic-simulation/military/Wargoal.cpp b/src/openvic-simulation/military/Wargoal.cpp index afb1a24..773e791 100644 --- a/src/openvic-simulation/military/Wargoal.cpp +++ b/src/openvic-simulation/military/Wargoal.cpp @@ -1,5 +1,7 @@ #include "Wargoal.hpp" +#include + #include "openvic-simulation/dataloader/NodeTools.hpp" using namespace OpenVic; @@ -68,11 +70,18 @@ bool WargoalTypeManager::add_wargoal_type( }); } -bool WargoalTypeManager::load_wargoal_file(ast::NodeCPtr root) { +bool WargoalTypeManager::load_wargoal_file(ovdl::v2script::Parser const& parser) { + using namespace std::string_view_literals; + ovdl::symbol peace_order_symbol = parser.find_intern("peace_order"sv); + if (!peace_order_symbol) { + Logger::error("peace_order could not be interned."); + } + bool ret = expect_dictionary_reserve_length( wargoal_types, - [this](std::string_view identifier, ast::NodeCPtr value) -> bool { - if (identifier == "peace_order") { + [this, &peace_order_symbol](std::string_view identifier, ast::NodeCPtr value) -> bool { + // If peace_order_symbol is false, we know there is no peace_order string in the parser + if (peace_order_symbol && identifier == peace_order_symbol.c_str()) { return true; } @@ -187,11 +196,11 @@ bool WargoalTypeManager::load_wargoal_file(ast::NodeCPtr root) { ); return ret; } - )(root); + )(parser.get_file_node()); /* load order in which CBs are prioritised by AI */ ret &= expect_key( - "peace_order", + peace_order_symbol, expect_list( expect_wargoal_type_identifier( [this](WargoalType const& wargoal) -> bool { @@ -205,7 +214,7 @@ bool WargoalTypeManager::load_wargoal_file(ast::NodeCPtr root) { true // warn instead of error ) ) - )(root); + )(parser.get_file_node()); lock_wargoal_types(); return ret; -- cgit v1.2.3-56-ga3b1