From e67c196d2a44dce1387e5d91d37aa519bb70ddf0 Mon Sep 17 00:00:00 2001 From: get <45425365+Minty-Meeo@users.noreply.github.com> Date: Fri, 16 Jun 2023 19:33:38 -0500 Subject: [PATCH] DolphinTool: Less string copies --- Source/Core/DolphinTool/ConvertCommand.cpp | 23 ++++++++++------------ Source/Core/DolphinTool/HeaderCommand.cpp | 2 +- Source/Core/DolphinTool/VerifyCommand.cpp | 16 +++++++-------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/Source/Core/DolphinTool/ConvertCommand.cpp b/Source/Core/DolphinTool/ConvertCommand.cpp index d96e571d28..d8cf7b96f2 100644 --- a/Source/Core/DolphinTool/ConvertCommand.cpp +++ b/Source/Core/DolphinTool/ConvertCommand.cpp @@ -61,9 +61,11 @@ int ConvertCommand(const std::vector& args) parser.usage("usage: convert [options]... [FILE]..."); parser.add_option("-u", "--user") + .type("string") .action("store") .help("User folder path, required for temporary processing files. " - "Will be automatically created if this option is not set."); + "Will be automatically created if this option is not set.") + .set_default(""); parser.add_option("-i", "--input") .type("string") @@ -110,34 +112,29 @@ int ConvertCommand(const std::vector& args) // Initialize the dolphin user directory, required for temporary processing files // If this is not set, destructive file operations could occur due to path confusion - std::string user_directory; - if (options.is_set("user")) - user_directory = static_cast(options.get("user")); - - UICommon::SetUserDirectory(user_directory); + UICommon::SetUserDirectory(options["user"]); UICommon::Init(); // Validate options // --input - const std::string input_file_path = static_cast(options.get("input")); - if (input_file_path.empty()) + if (!options.is_set("input")) { std::cerr << "Error: No input set" << std::endl; return EXIT_FAILURE; } + const std::string& input_file_path = options["input"]; // --output - const std::string output_file_path = static_cast(options.get("output")); - if (output_file_path.empty()) + if (!options.is_set("output")) { std::cerr << "Error: No output set" << std::endl; return EXIT_FAILURE; } + const std::string& output_file_path = options["output"]; // --format - const std::optional format_o = - ParseFormatString(static_cast(options.get("format"))); + const std::optional format_o = ParseFormatString(options["format"]); if (!format_o.has_value()) { std::cerr << "Error: No output format set" << std::endl; @@ -255,7 +252,7 @@ int ConvertCommand(const std::vector& args) // --compress, --compress_level std::optional compression_o = - ParseCompressionTypeString(static_cast(options.get("compression"))); + ParseCompressionTypeString(options["compression"]); std::optional compression_level_o; if (options.is_set("compression_level")) diff --git a/Source/Core/DolphinTool/HeaderCommand.cpp b/Source/Core/DolphinTool/HeaderCommand.cpp index aba6c0883f..96099d94d4 100644 --- a/Source/Core/DolphinTool/HeaderCommand.cpp +++ b/Source/Core/DolphinTool/HeaderCommand.cpp @@ -43,7 +43,7 @@ int HeaderCommand(const std::vector& args) const optparse::Values& options = parser.parse_args(args); // Validate options - const std::string input_file_path = static_cast(options.get("input")); + const std::string& input_file_path = options["input"]; if (input_file_path.empty()) { std::cerr << "Error: No input set" << std::endl; diff --git a/Source/Core/DolphinTool/VerifyCommand.cpp b/Source/Core/DolphinTool/VerifyCommand.cpp index 3c3af0d358..5dd353ead0 100644 --- a/Source/Core/DolphinTool/VerifyCommand.cpp +++ b/Source/Core/DolphinTool/VerifyCommand.cpp @@ -80,9 +80,11 @@ int VerifyCommand(const std::vector& args) parser.usage("usage: verify [options]..."); parser.add_option("-u", "--user") + .type("string") .action("store") .help("User folder path, required for temporary processing files. " - "Will be automatically created if this option is not set."); + "Will be automatically created if this option is not set.") + .set_default(""); parser.add_option("-i", "--input") .type("string") @@ -101,20 +103,16 @@ int VerifyCommand(const std::vector& args) // Initialize the dolphin user directory, required for temporary processing files // If this is not set, destructive file operations could occur due to path confusion - std::string user_directory; - if (options.is_set("user")) - user_directory = static_cast(options.get("user")); - - UICommon::SetUserDirectory(user_directory); + UICommon::SetUserDirectory(options["user"]); UICommon::Init(); // Validate options - const std::string input_file_path = static_cast(options.get("input")); - if (input_file_path.empty()) + if (!options.is_set("input")) { std::cerr << "Error: No input set" << std::endl; return EXIT_FAILURE; } + const std::string& input_file_path = options["input"]; DiscIO::Hashes hashes_to_calculate{}; const bool algorithm_is_set = options.is_set("algorithm"); @@ -124,7 +122,7 @@ int VerifyCommand(const std::vector& args) } else { - const std::string algorithm = static_cast(options.get("algorithm")); + const std::string& algorithm = options["algorithm"]; if (algorithm == "crc32") hashes_to_calculate.crc32 = true; else if (algorithm == "md5")