From f0283435f6f7b48b289d4bb0a6b9422e97439220 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sun, 19 Aug 2018 09:45:08 +0100 Subject: [PATCH] Remove unnecessary Boost header includes Don't bother using Boost.Format for exception messages, just concat strings, and don't unnecessarily use case-insensitive comparisons for message types. --- src/api/api_database.cpp | 2 -- src/api/game/game_cache.cpp | 1 - src/api/game/load_order_handler.cpp | 7 +------ src/api/helpers/crc.cpp | 8 +++----- src/api/helpers/git_helper.cpp | 5 +---- src/api/masterlist.cpp | 3 --- src/api/metadata/condition_evaluator.cpp | 25 +++++++----------------- src/api/metadata/condition_grammar.h | 14 ++++++------- src/api/metadata/group.cpp | 2 -- src/api/metadata/yaml/message.h | 5 ++--- src/api/metadata_list.cpp | 1 - src/api/plugin.cpp | 5 +---- src/api/plugin.h | 1 - src/api/sorting/plugin_sorting_data.cpp | 2 ++ 14 files changed, 23 insertions(+), 58 deletions(-) diff --git a/src/api/api_database.cpp b/src/api/api_database.cpp index cde20450..dcdbb216 100644 --- a/src/api/api_database.cpp +++ b/src/api/api_database.cpp @@ -27,8 +27,6 @@ #include #include -#include - #include "api/game/game.h" #include "api/metadata/condition_evaluator.h" #include "api/metadata/yaml/plugin_metadata.h" diff --git a/src/api/game/game_cache.cpp b/src/api/game/game_cache.cpp index 750bf71a..50529c10 100644 --- a/src/api/game/game_cache.cpp +++ b/src/api/game/game_cache.cpp @@ -26,7 +26,6 @@ #include -#include #include using boost::locale::to_lower; diff --git a/src/api/game/load_order_handler.cpp b/src/api/game/load_order_handler.cpp index 294bd949..094288a0 100644 --- a/src/api/game/load_order_handler.cpp +++ b/src/api/game/load_order_handler.cpp @@ -24,13 +24,9 @@ #include "api/game/load_order_handler.h" -#include -#include - #include "api/helpers/logging.h" #include "loot/exception/error_categories.h" -using boost::format; using std::string; namespace loot { @@ -194,8 +190,7 @@ void LoadOrderHandler::HandleError(const std::string& operation, err = "libloadorder failed to " + operation + ". Details could not be fetched."; } else { - err = (format("libloadorder failed to " + operation + ". Details: %1%") % e) - .str(); + err = "libloadorder failed to " + operation + ". Details: " + e; } auto logger = getLogger(); diff --git a/src/api/helpers/crc.cpp b/src/api/helpers/crc.cpp index f35e03b4..6e4c36e4 100644 --- a/src/api/helpers/crc.cpp +++ b/src/api/helpers/crc.cpp @@ -26,7 +26,7 @@ #include #include -#include + #include "api/helpers/logging.h" #include "loot/exception/file_access_error.h" @@ -77,10 +77,8 @@ uint32_t GetCrc32(const boost::filesystem::path& filename) { return checksum; } catch (std::exception& e) { - throw FileAccessError( - (boost::format("Unable to open \"%1%\" for CRC calculation: %2%") % - filename.string() % e.what()) - .str()); + throw FileAccessError("Unable to open \"" + filename.string() + + "\" for CRC calulation: " + e.what()); } } } diff --git a/src/api/helpers/git_helper.cpp b/src/api/helpers/git_helper.cpp index c57c3fe1..5c31cd87 100644 --- a/src/api/helpers/git_helper.cpp +++ b/src/api/helpers/git_helper.cpp @@ -27,8 +27,6 @@ #include #include -#include - #include "api/helpers/logging.h" #include "loot/exception/error_categories.h" #include "loot/exception/git_state_error.h" @@ -154,8 +152,7 @@ void GitHelper::Call(int error_code) { gitError = std::to_string(error_code) + "; " + last_error->message; giterr_clear(); - auto message = - (boost::format("Git operation failed. Details: %1%") % gitError).str(); + auto message = "Git operation failed. Details: " + gitError; throw std::system_error(error_code, libgit2_category(), message); } diff --git a/src/api/masterlist.cpp b/src/api/masterlist.cpp index 8559514a..9700a082 100644 --- a/src/api/masterlist.cpp +++ b/src/api/masterlist.cpp @@ -24,15 +24,12 @@ #include "api/masterlist.h" -#include - #include "api/game/game.h" #include "api/helpers/git_helper.h" #include "api/helpers/logging.h" #include "loot/exception/file_access_error.h" #include "loot/exception/git_state_error.h" -using boost::format; using std::string; namespace fs = boost::filesystem; diff --git a/src/api/metadata/condition_evaluator.cpp b/src/api/metadata/condition_evaluator.cpp index 8e0d6c04..8e6a1a13 100644 --- a/src/api/metadata/condition_evaluator.cpp +++ b/src/api/metadata/condition_evaluator.cpp @@ -24,16 +24,11 @@ #include "api/metadata/condition_evaluator.h" -#include -#include - #include "api/helpers/crc.h" #include "api/helpers/logging.h" #include "api/metadata/condition_grammar.h" #include "loot/exception/condition_syntax_error.h" -using boost::format; - namespace loot { ConditionEvaluator::ConditionEvaluator() : gameType_(GameType::tes4), @@ -318,8 +313,7 @@ void ConditionEvaluator::validatePath(const boost::filesystem::path& path) { continue; if (component == ".." && temp.filename() == "..") { - throw ConditionSyntaxError( - (format("Invalid file path: %1%") % path.string()).str()); + throw ConditionSyntaxError("Invalid file path: " + path.string()); } temp /= component; @@ -329,9 +323,8 @@ void ConditionEvaluator::validateRegex(const std::string& regexString) { try { std::regex(regexString, std::regex::ECMAScript | std::regex::icase); } catch (std::regex_error& e) { - throw ConditionSyntaxError( - (format("Invalid regex string \"%1%\": %2%") % regexString % e.what()) - .str()); + throw ConditionSyntaxError("Invalid regex string \"" + regexString + + "\": " + e.what()); } } @@ -373,9 +366,8 @@ std::pair ConditionEvaluator::splitRegex( try { reg = std::regex(filename, std::regex::ECMAScript | std::regex::icase); } catch (std::regex_error& e) { - throw ConditionSyntaxError( - (format("Invalid regex string \"%1%\": %2%") % filename % e.what()) - .str()); + throw ConditionSyntaxError("Invalid regex string \"" + filename + + "\": " + e.what()); } return std::pair(parent, reg); @@ -445,11 +437,8 @@ bool ConditionEvaluator::parseCondition(const std::string& condition) const { boost::spirit::qi::phrase_parse(begin, end, grammar, skipper, evaluation); if (!parseResult || begin != end) { - throw ConditionSyntaxError( - (boost::format("Failed to parse condition \"%1%\": only partially " - "matched expected syntax.") % - condition) - .str()); + throw ConditionSyntaxError("Failed to parse condition \"" + condition + + "\": only partially matched expected syntax."); } return evaluation; diff --git a/src/api/metadata/condition_grammar.h b/src/api/metadata/condition_grammar.h index b484ccd2..10f976f9 100644 --- a/src/api/metadata/condition_grammar.h +++ b/src/api/metadata/condition_grammar.h @@ -33,15 +33,15 @@ #define BOOST_SPIRIT_USE_PHOENIX_V3 1 #endif +#include +#include + #include #include -#include #include #include #include #include -#include -#include #include "api/game/game.h" #include "api/helpers/logging.h" @@ -286,11 +286,9 @@ private: std::string context(errorpos, last); boost::trim(context); - throw ConditionSyntaxError( - (boost::format("Failed to parse condition \"%1%\": expected \"%2%\" at " - "\"%3%\".") % - condition % what.tag % context) - .str()); + throw ConditionSyntaxError("Failed to parse condition \"" + condition + + "\": expected \"" + what.tag + "\" at \"" + + context + "\"."); } boost::spirit::qi::rule expression_, compound_, diff --git a/src/api/metadata/group.cpp b/src/api/metadata/group.cpp index 742e7d9a..ef062115 100644 --- a/src/api/metadata/group.cpp +++ b/src/api/metadata/group.cpp @@ -24,8 +24,6 @@ #include "loot/metadata/group.h" -#include - #include "api/metadata/yaml/group.h" namespace loot { diff --git a/src/api/metadata/yaml/message.h b/src/api/metadata/yaml/message.h index ba618b38..73e8abc9 100644 --- a/src/api/metadata/yaml/message.h +++ b/src/api/metadata/yaml/message.h @@ -28,7 +28,6 @@ #include #include -#include #include #include "loot/metadata/message.h" @@ -70,9 +69,9 @@ struct convert { type = node["type"].as(); loot::MessageType typeNo = loot::MessageType::say; - if (boost::iequals(type, "warn")) + if (type == "warn") typeNo = loot::MessageType::warn; - else if (boost::iequals(type, "error")) + else if (type == "error") typeNo = loot::MessageType::error; std::vector content; diff --git a/src/api/metadata_list.cpp b/src/api/metadata_list.cpp index f6486ebe..231d73a2 100644 --- a/src/api/metadata_list.cpp +++ b/src/api/metadata_list.cpp @@ -24,7 +24,6 @@ #include "api/metadata_list.h" -#include #include #include "api/game/game.h" diff --git a/src/api/plugin.cpp b/src/api/plugin.cpp index 88f42bd7..39768482 100644 --- a/src/api/plugin.cpp +++ b/src/api/plugin.cpp @@ -28,7 +28,6 @@ #include #include -#include #include #include "api/game/game.h" @@ -125,9 +124,7 @@ Plugin::Plugin(const GameType gameType, logger->error( "Cannot read plugin file \"{}\". Details: {}", name_, e.what()); } - throw FileAccessError( - (boost::format("Cannot read \"%1%\". Details: %2%") % name % e.what()) - .str()); + throw FileAccessError("Cannot read \"" + name + "\". Details: " + e.what()); } if (logger) { diff --git a/src/api/plugin.h b/src/api/plugin.h index ada5faba..1b2ed5db 100644 --- a/src/api/plugin.h +++ b/src/api/plugin.h @@ -31,7 +31,6 @@ #include #include -#include #include #include "api/game/load_order_handler.h" diff --git a/src/api/sorting/plugin_sorting_data.cpp b/src/api/sorting/plugin_sorting_data.cpp index 1966aa24..ed975513 100644 --- a/src/api/sorting/plugin_sorting_data.cpp +++ b/src/api/sorting/plugin_sorting_data.cpp @@ -24,6 +24,8 @@ #include "plugin_sorting_data.h" +#include + namespace loot { PluginSortingData::PluginSortingData(const Plugin& plugin, const PluginMetadata&& metadata) :