aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/military/Wargoal.cpp
diff options
context:
space:
mode:
author Spartan322 <Megacake1234@gmail.com>2024-07-06 16:40:57 +0200
committer Spartan322 <Megacake1234@gmail.com>2024-07-18 04:20:15 +0200
commitd236dcf30c001e540377184565f4d173ed56f76e (patch)
tree3f2a270b5b85f91a22289091084a30c105f10f4d /src/openvic-simulation/military/Wargoal.cpp
parent93d095ba30747c7158882668577c854be7ea39a1 (diff)
Optimize some string interning casesoptimize/string-interning
Diffstat (limited to 'src/openvic-simulation/military/Wargoal.cpp')
-rw-r--r--src/openvic-simulation/military/Wargoal.cpp21
1 files changed, 15 insertions, 6 deletions
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 <openvic-dataloader/v2script/Parser.hpp>
+
#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<char> 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;