aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/economy
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/economy
parent93d095ba30747c7158882668577c854be7ea39a1 (diff)
Optimize some string interning casesoptimize/string-interning
Diffstat (limited to 'src/openvic-simulation/economy')
-rw-r--r--src/openvic-simulation/economy/EconomyManager.hpp5
-rw-r--r--src/openvic-simulation/economy/ProductionType.cpp20
-rw-r--r--src/openvic-simulation/economy/ProductionType.hpp4
3 files changed, 20 insertions, 9 deletions
diff --git a/src/openvic-simulation/economy/EconomyManager.hpp b/src/openvic-simulation/economy/EconomyManager.hpp
index 668774d..2464912 100644
--- a/src/openvic-simulation/economy/EconomyManager.hpp
+++ b/src/openvic-simulation/economy/EconomyManager.hpp
@@ -3,6 +3,7 @@
#include "openvic-simulation/economy/BuildingType.hpp"
#include "openvic-simulation/economy/GoodDefinition.hpp"
#include "openvic-simulation/economy/ProductionType.hpp"
+#include "openvic-dataloader/v2script/Parser.hpp"
namespace OpenVic {
struct EconomyManager {
@@ -12,8 +13,8 @@ namespace OpenVic {
ProductionTypeManager PROPERTY_REF(production_type_manager);
public:
- inline bool load_production_types_file(PopManager const& pop_manager, ast::NodeCPtr root) {
- return production_type_manager.load_production_types_file(good_definition_manager, pop_manager, root);
+ inline bool load_production_types_file(PopManager const& pop_manager, ovdl::v2script::Parser const& parser) {
+ return production_type_manager.load_production_types_file(good_definition_manager, pop_manager, parser);
}
inline bool load_buildings_file(ModifierManager& modifier_manager, ast::NodeCPtr root) {
diff --git a/src/openvic-simulation/economy/ProductionType.cpp b/src/openvic-simulation/economy/ProductionType.cpp
index 9b5a42b..65f3eba 100644
--- a/src/openvic-simulation/economy/ProductionType.cpp
+++ b/src/openvic-simulation/economy/ProductionType.cpp
@@ -1,5 +1,7 @@
#include "ProductionType.hpp"
+#include <openvic-dataloader/v2script/Parser.hpp>
+
using namespace OpenVic;
using namespace OpenVic::NodeTools;
@@ -176,21 +178,27 @@ bool ProductionTypeManager::add_production_type(
}
bool ProductionTypeManager::load_production_types_file(
- GoodDefinitionManager const& good_definition_manager, PopManager const& pop_manager, ast::NodeCPtr root
+ GoodDefinitionManager const& good_definition_manager, PopManager const& pop_manager, ovdl::v2script::Parser const& parser
) {
+ using namespace std::string_view_literals;
+ auto template_symbol = parser.find_intern("template"sv);
+ if (!template_symbol) {
+ Logger::error("template could not be interned.");
+ }
+
size_t expected_types = 0;
/* Pass #1: find and store template identifiers */
ordered_set<std::string_view> templates;
ordered_map<std::string_view, std::string_view> template_target_map;
bool ret = expect_dictionary(
- [this, &expected_types, &templates, &template_target_map](std::string_view key, ast::NodeCPtr value) -> bool {
+ [this, &expected_types, &templates, &template_target_map, &template_symbol](std::string_view key, ast::NodeCPtr value) -> bool {
expected_types++;
std::string_view template_id = "";
bool found_template = false;
const bool ret =
- expect_key("template", expect_identifier(assign_variable_callback(template_id)), &found_template)(value);
+ expect_key(template_symbol, expect_identifier(assign_variable_callback(template_id)), &found_template)(value);
if (found_template) {
if (ret) {
templates.emplace(template_id);
@@ -202,7 +210,7 @@ bool ProductionTypeManager::load_production_types_file(
}
return true;
}
- )(root);
+ )(parser.get_file_node());
/* Pass #2: create and populate the template map */
ordered_map<std::string_view, ast::NodeCPtr> template_node_map;
@@ -214,7 +222,7 @@ bool ProductionTypeManager::load_production_types_file(
}
return true;
}
- )(root);
+ )(parser.get_file_node());
/* Pass #3: actually load production types */
reserve_more_production_types(expected_types);
@@ -297,7 +305,7 @@ bool ProductionTypeManager::load_production_types_file(
);
return ret;
}
- )(root);
+ )(parser.get_file_node());
production_types.lock();
diff --git a/src/openvic-simulation/economy/ProductionType.hpp b/src/openvic-simulation/economy/ProductionType.hpp
index ed3b84f..5394938 100644
--- a/src/openvic-simulation/economy/ProductionType.hpp
+++ b/src/openvic-simulation/economy/ProductionType.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include <openvic-dataloader/v2script/Parser.hpp>
+
#include "openvic-simulation/economy/GoodDefinition.hpp"
#include "openvic-simulation/pop/Pop.hpp"
#include "openvic-simulation/scripts/ConditionScript.hpp"
@@ -111,7 +113,7 @@ namespace OpenVic {
);
bool load_production_types_file(
- GoodDefinitionManager const& good_definition_manager, PopManager const& pop_manager, ast::NodeCPtr root
+ GoodDefinitionManager const& good_definition_manager, PopManager const& pop_manager, ovdl::v2script::Parser const& parser
);
bool parse_scripts(DefinitionManager const& definition_manager);