From dd10547ac23bdd9f834ab9864162978ef8105cd7 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 3 Jun 2019 20:57:52 -0400 Subject: [PATCH] setsys_settings_items: Less resource churn with combined key/value construction The previous string construction discards two temporary std::string instances (operator+ returns by value, not by reference), and creates a std::string that it doesn't need to (the one around key). Instead we can just append to the end of the initial std::string itself, saving on two unnecessary created strings. append() has a const char* overload as well (as does operator+), so we can just append the key string as is without creating an entire new string. --- .../source/set_mitm/setsys_settings_items.cpp | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/stratosphere/ams_mitm/source/set_mitm/setsys_settings_items.cpp b/stratosphere/ams_mitm/source/set_mitm/setsys_settings_items.cpp index e19965119..0f795e84c 100644 --- a/stratosphere/ams_mitm/source/set_mitm/setsys_settings_items.cpp +++ b/stratosphere/ams_mitm/source/set_mitm/setsys_settings_items.cpp @@ -153,8 +153,8 @@ static Result ParseValue(const char *name, const char *key, const char *val_tup) if (delimiter == NULL || value_len == 0 || type_len == 0) { return ResultSettingsItemValueInvalidFormat; } - - std::string kv = std::string(name) + "!" + std::string(key); + + std::string kv = std::string(name).append("!").append(key); SettingsItemValue value; if (strncasecmp(type, "str", type_len) == 0 || strncasecmp(type, "string", type_len) == 0) { @@ -242,7 +242,7 @@ static int SettingsItemIniHandler(void *user, const char *name, const char *key, return R_SUCCEEDED(rc) ? 1 : 0; } -void SettingsItemManager::LoadConfiguration() { +void SettingsItemManager::LoadConfiguration() { /* Open file. */ FsFile config_file; Result rc = Utils::OpenSdFile("/atmosphere/system_settings.ini", FS_OPEN_READ, &config_file); @@ -275,31 +275,31 @@ void SettingsItemManager::LoadConfiguration() { } Result SettingsItemManager::GetValueSize(const char *name, const char *key, u64 *out_size) { - std::string kv = std::string(name) + "!" + std::string(key); - + const std::string kv = std::string(name).append("!").append(key); + auto it = g_settings_items.find(kv); if (it == g_settings_items.end()) { return ResultSettingsItemNotFound; } - + *out_size = it->second.size; return ResultSuccess; } Result SettingsItemManager::GetValue(const char *name, const char *key, void *out, size_t max_size, u64 *out_size) { - std::string kv = std::string(name) + "!" + std::string(key); - + const std::string kv = std::string(name).append("!").append(key); + auto it = g_settings_items.find(kv); if (it == g_settings_items.end()) { return ResultSettingsItemNotFound; } - + size_t copy_size = it->second.size; if (max_size < copy_size) { copy_size = max_size; } *out_size = copy_size; - + memcpy(out, it->second.data, copy_size); return ResultSuccess; }