Skip to content

Commit 9abb7f2

Browse files
committed
Apply performance recommendations from clang-tidy
1 parent 56c1951 commit 9abb7f2

29 files changed

+132
-115
lines changed

src/headless/main.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ static bool run_headless(Dataloader::path_vector_t const& roots, bool run_tests)
7272

7373
if (run_tests) {
7474
Testing testing { game_manager.get_definition_manager() };
75-
std::cout << std::endl << "Testing Loaded" << std::endl << std::endl;
75+
std::cout << '\n' << "Testing Loaded" << '\n' << '\n';
7676
testing.execute_all_scripts();
7777
testing.report_results();
78-
std::cout << "Testing Executed" << std::endl << std::endl;
78+
std::cout << "Testing Executed" << '\n' << '\n';
7979
}
8080

8181
Logger::info("===== Setting up instance... =====");
@@ -166,14 +166,14 @@ int main(int argc, char const* argv[]) {
166166
if (!root.empty()) {
167167
return true;
168168
} else {
169-
std::cerr << "Empty path after giving \"" << path << "\" to " << path_use
170-
<< " command line argument \"" << command << "\"." << std::endl;
169+
std::cerr << "Empty path after giving \"" << path << "\" to " << path_use << " command line argument \""
170+
<< command << "\"." << '\n';
171171
}
172172
} else {
173-
std::cerr << "Missing path after " << path_use << " command line argument \"" << command << "\"." << std::endl;
173+
std::cerr << "Missing path after " << path_use << " command line argument \"" << command << "\"." << '\n';
174174
}
175175
} else {
176-
std::cerr << "Duplicate " << path_use << " command line argument \"-b\"." << std::endl;
176+
std::cerr << "Duplicate " << path_use << " command line argument \"-b\"." << '\n';
177177
}
178178
print_help(std::cerr, program_name);
179179
return false;
@@ -201,7 +201,7 @@ int main(int argc, char const* argv[]) {
201201
if (root.empty()) {
202202
root = Dataloader::search_for_game_path();
203203
if (root.empty()) {
204-
std::cerr << "Search for base directory path failed!" << std::endl;
204+
std::cerr << "Search for base directory path failed!" << '\n';
205205
print_help(std::cerr, program_name);
206206
return -1;
207207
}
@@ -212,16 +212,16 @@ int main(int argc, char const* argv[]) {
212212
roots.emplace_back(root / mod_directory / argv[argn++]);
213213
}
214214

215-
std::cout << "!!! HEADLESS SIMULATION START !!!" << std::endl;
215+
std::cout << "!!! HEADLESS SIMULATION START !!!" << '\n';
216216

217217
const bool ret = run_headless(roots, run_tests);
218218

219-
std::cout << "!!! HEADLESS SIMULATION END !!!" << std::endl;
219+
std::cout << "!!! HEADLESS SIMULATION END !!!" << '\n';
220220

221-
std::cout << "\nLoad returned: " << (ret ? "SUCCESS" : "FAILURE") << std::endl;
221+
std::cout << "\nLoad returned: " << (ret ? "SUCCESS" : "FAILURE") << '\n';
222222

223223
std::cout << "\nLogger Summary: Info = " << Logger::get_info_count() << ", Warning = " << Logger::get_warning_count()
224-
<< ", Error = " << Logger::get_error_count() << std::endl;
224+
<< ", Error = " << Logger::get_error_count() << '\n';
225225

226226
return ret ? 0 : -1;
227227
}

src/openvic-simulation/GameManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ bool GameManager::set_roots(Dataloader::path_vector_t const& roots) {
1616
return true;
1717
}
1818

19-
bool GameManager::load_definitions(Dataloader::localisation_callback_t localisation_callback) {
19+
bool GameManager::load_definitions(Dataloader::localisation_callback_t const& localisation_callback) {
2020
if (definitions_loaded) {
2121
Logger::error("Cannot load definitions - already loaded!");
2222
return false;

src/openvic-simulation/GameManager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace OpenVic {
3333

3434
bool set_roots(Dataloader::path_vector_t const& roots);
3535

36-
bool load_definitions(Dataloader::localisation_callback_t localisation_callback);
36+
bool load_definitions(Dataloader::localisation_callback_t const& localisation_callback);
3737

3838
bool setup_instance(Bookmark const* bookmark);
3939

src/openvic-simulation/dataloader/Dataloader.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fs::path Dataloader::lookup_file(std::string_view path, bool print_error) const
7575
std::error_code ec;
7676
for (fs::directory_entry const& entry : fs::directory_iterator { composed.parent_path(), ec }) {
7777
if (entry.is_regular_file()) {
78-
const fs::path file = entry;
78+
fs::path const& file = entry;
7979
if (StringUtils::strings_equal_case_insensitive(file.filename().string(), filename)) {
8080
return file;
8181
}
@@ -1171,10 +1171,10 @@ static bool _load_localisation_file(Dataloader::localisation_callback_t callback
11711171
return ret;
11721172
}
11731173

1174-
bool Dataloader::load_localisation_files(localisation_callback_t callback, std::string_view localisation_dir) const {
1175-
return apply_to_files(
1174+
bool Dataloader::load_localisation_files(localisation_callback_t const& callback, std::string_view localisation_dir) const {
1175+
return apply_to_files( //
11761176
lookup_files_in_dir(localisation_dir, ".csv"),
1177-
[callback](fs::path path) -> bool {
1177+
[callback](fs::path const& path) -> bool {
11781178
return _load_localisation_file(callback, parse_csv(path).get_lines());
11791179
}
11801180
);

src/openvic-simulation/dataloader/Dataloader.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ namespace OpenVic {
8989
/// a non-empty hint_path, performs empty path behavior.
9090
/// @return fs::path The root directory of a valid Victoria 2 install, or an empty path.
9191
///
92-
static fs::path search_for_game_path(fs::path hint_path = {});
92+
static fs::path search_for_game_path(fs::path const& hint_path = {});
9393

9494
/* In reverse-load order, so base defines first and final loaded mod last */
9595
bool set_roots(path_vector_t const& new_roots);
@@ -137,7 +137,7 @@ namespace OpenVic {
137137
/* Args: key, locale, localisation */
138138
using localisation_callback_t = NodeTools::callback_t<std::string_view, locale_t, std::string_view>;
139139
bool load_localisation_files(
140-
localisation_callback_t callback, std::string_view localisation_dir = "localisation"
140+
localisation_callback_t const& callback, std::string_view localisation_dir = "localisation"
141141
) const;
142142
};
143143
}

src/openvic-simulation/dataloader/NodeTools.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,15 @@ callback_t<std::string_view> NodeTools::expect_date_str(callback_t<Date> callbac
227227
};
228228
}
229229

230-
node_callback_t NodeTools::expect_date(callback_t<Date> callback) {
230+
node_callback_t NodeTools::expect_date(callback_t<Date> const& callback) {
231231
return expect_identifier(expect_date_str(callback));
232232
}
233233

234-
node_callback_t NodeTools::expect_date_string(callback_t<Date> callback) {
234+
node_callback_t NodeTools::expect_date_string(callback_t<Date> const& callback) {
235235
return expect_string(expect_date_str(callback));
236236
}
237237

238-
node_callback_t NodeTools::expect_date_identifier_or_string(callback_t<Date> callback) {
238+
node_callback_t NodeTools::expect_date_identifier_or_string(callback_t<Date> const& callback) {
239239
return expect_identifier_or_string(expect_date_str(callback));
240240
}
241241

@@ -375,7 +375,7 @@ node_callback_t NodeTools::expect_list_and_length(length_callback_t length_callb
375375
});
376376
}
377377

378-
node_callback_t NodeTools::expect_list_of_length(size_t length, node_callback_t callback) {
378+
node_callback_t NodeTools::expect_list_of_length(size_t length, node_callback_t const& callback) {
379379
return [length, callback](ast::NodeCPtr node) -> bool {
380380
bool size_ret = true;
381381
bool ret = expect_list_and_length(
@@ -395,7 +395,7 @@ node_callback_t NodeTools::expect_list_of_length(size_t length, node_callback_t
395395
};
396396
}
397397

398-
node_callback_t NodeTools::expect_list(node_callback_t callback) {
398+
node_callback_t NodeTools::expect_list(node_callback_t const& callback) {
399399
return expect_list_and_length(default_length_callback, callback);
400400
}
401401

@@ -492,11 +492,13 @@ NodeTools::expect_key(ovdl::symbol<char> key, node_callback_t callback, bool* ke
492492
return _expect_key(key, callback, key_found, allow_duplicates);
493493
}
494494

495-
node_callback_t NodeTools::expect_dictionary_and_length(length_callback_t length_callback, key_value_callback_t callback) {
495+
node_callback_t NodeTools::expect_dictionary_and_length( //
496+
length_callback_t const& length_callback, key_value_callback_t const& callback
497+
) {
496498
return expect_list_and_length(length_callback, expect_assign(callback));
497499
}
498500

499-
node_callback_t NodeTools::expect_dictionary(key_value_callback_t callback) {
501+
node_callback_t NodeTools::expect_dictionary(key_value_callback_t const& callback) {
500502
return expect_dictionary_and_length(default_length_callback, callback);
501503
}
502504

src/openvic-simulation/dataloader/NodeTools.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ using namespace std::string_view_literals;
191191
node_callback_t expect_text_format(callback_t<text_format_t> callback);
192192

193193
callback_t<std::string_view> expect_date_str(callback_t<Date> callback);
194-
node_callback_t expect_date(callback_t<Date> callback);
195-
node_callback_t expect_date_string(callback_t<Date> callback);
196-
node_callback_t expect_date_identifier_or_string(callback_t<Date> callback);
194+
node_callback_t expect_date(callback_t<Date> const& callback);
195+
node_callback_t expect_date_string(callback_t<Date> const& callback);
196+
node_callback_t expect_date_identifier_or_string(callback_t<Date> const& callback);
197197
node_callback_t expect_years(callback_t<Timespan> callback);
198198
node_callback_t expect_months(callback_t<Timespan> callback);
199199
node_callback_t expect_days(callback_t<Timespan> callback);
@@ -210,8 +210,8 @@ using namespace std::string_view_literals;
210210
};
211211

212212
node_callback_t expect_list_and_length(length_callback_t length_callback, node_callback_t callback);
213-
node_callback_t expect_list_of_length(size_t length, node_callback_t callback);
214-
node_callback_t expect_list(node_callback_t callback);
213+
node_callback_t expect_list_of_length(size_t length, node_callback_t const& callback);
214+
node_callback_t expect_list(node_callback_t const& callback);
215215
node_callback_t expect_length(callback_t<size_t> callback);
216216

217217
node_callback_t expect_key(
@@ -222,8 +222,10 @@ using namespace std::string_view_literals;
222222
std::string_view key, node_callback_t callback, bool* key_found = nullptr, bool allow_duplicates = false
223223
);
224224

225-
node_callback_t expect_dictionary_and_length(length_callback_t length_callback, key_value_callback_t callback);
226-
node_callback_t expect_dictionary(key_value_callback_t callback);
225+
node_callback_t expect_dictionary_and_length( //
226+
length_callback_t const& length_callback, key_value_callback_t const& callback
227+
);
228+
node_callback_t expect_dictionary(key_value_callback_t const& callback);
227229

228230
struct dictionary_entry_t {
229231
enum class expected_count_t : uint8_t {

src/openvic-simulation/dataloader/Vic2PathSearch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ static fs::path _search_for_game_path(fs::path hint_path = {}) {
334334
return ""; // The supplied path fits literally none of the criteria
335335
}
336336

337-
fs::path Dataloader::search_for_game_path(fs::path hint_path) {
337+
fs::path Dataloader::search_for_game_path(fs::path const& hint_path) {
338338
struct fshash {
339339
size_t operator()(std::filesystem::path const& p) const noexcept {
340340
return std::filesystem::hash_value(p);

src/openvic-simulation/diplomacy/DiplomaticAction.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
using namespace OpenVic;
1414

1515
DiplomaticActionType::DiplomaticActionType(DiplomaticActionType::Initializer&& initializer)
16-
: commit_action_caller { std::move(initializer.commit) }, allowed_to_commit { std::move(initializer.allowed) },
17-
get_acceptance { std::move(initializer.get_acceptance) } {}
16+
: commit_action_caller { initializer.commit }, allowed_to_commit { initializer.allowed },
17+
get_acceptance { initializer.get_acceptance } {}
1818

1919
CancelableDiplomaticActionType::CancelableDiplomaticActionType(CancelableDiplomaticActionType::Initializer&& initializer)
20-
: allowed_to_cancel { std::move(initializer.allowed_cancel) }, DiplomaticActionType { std::move(initializer) } {}
20+
: allowed_to_cancel { initializer.allowed_cancel }, DiplomaticActionType { std::move(initializer) } {}
2121

2222
bool DiplomaticActionManager::add_diplomatic_action(
2323
std::string_view identifier, DiplomaticActionType::Initializer&& initializer

src/openvic-simulation/interface/GFXObject.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ using namespace OpenVic;
77
using namespace OpenVic::GFX;
88
using namespace OpenVic::NodeTools;
99

10-
node_callback_t Object::expect_objects(length_callback_t length_callback, callback_t<std::unique_ptr<Object>&&> callback) {
10+
node_callback_t Object::expect_objects( //
11+
length_callback_t length_callback, callback_t<std::unique_ptr<Object>&&> const& callback
12+
) {
1113
return expect_dictionary_keys_and_length(
1214
length_callback,
1315

0 commit comments

Comments
 (0)