From 140a3a632731408fb5a79f74e93c79254c1eb2e5 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Thu, 15 Dec 2016 20:57:03 +0100 Subject: [PATCH] fix(config): Avoid double value lookup --- include/components/config.hpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/components/config.hpp b/include/components/config.hpp index 2cf216ec..0f3b4546 100644 --- a/include/components/config.hpp +++ b/include/components/config.hpp @@ -67,8 +67,8 @@ class config { template T get(const string& section, const string& key, const T& default_value) const { try { - T result{get(section, key)}; string string_value{get(section, key)}; + T result{convert(string{string_value})}; return dereference(move(section), move(key), move(string_value), move(result)); } catch (const key_error& err) { return default_value; @@ -93,7 +93,7 @@ class config { while (true) { try { string string_value{get(section, key + "-" + to_string(results.size()))}; - T value{get(section, key + "-" + to_string(results.size()))}; + T value{convert(string{string_value})}; if (!string_value.empty()) { results.emplace_back(dereference(section, key, move(string_value), move(value))); @@ -123,7 +123,7 @@ class config { while (true) { try { string string_value{get(section, key + "-" + to_string(results.size()))}; - T value{get(section, key + "-" + to_string(results.size()))}; + T value{convert(string{string_value})}; if (!string_value.empty()) { results.emplace_back(dereference(section, key, move(string_value), move(value))); @@ -220,8 +220,9 @@ class config { section = string_util::replace(section, "self", current_section, 0, 4); try { - T result{get(section, key)}; - return dereference(string(section), move(key), get(section, key), move(result)); + string string_value{get(section, key)}; + T result{convert(string{string_value})}; + return dereference(string(section), move(key), move(string_value), move(result)); } catch (const key_error& err) { throw value_error("Unexisting reference defined [" + section + "." + key + "]"); }