aboutsummaryrefslogtreecommitdiffstats
path: root/common/settings.h
diff options
context:
space:
mode:
authorMiodrag Milanovic <mmicko@gmail.com>2018-08-12 10:02:32 +0200
committerMiodrag Milanovic <mmicko@gmail.com>2018-08-12 10:02:32 +0200
commiteaf824ca73241014a280b1bd787d8f83e772dd05 (patch)
tree8954c2a92297446ed647f706602865d62f6f8502 /common/settings.h
parentb400cd8d7326ac798c9da76de3c2a11f2d96b6a7 (diff)
downloadnextpnr-eaf824ca73241014a280b1bd787d8f83e772dd05.tar.gz
nextpnr-eaf824ca73241014a280b1bd787d8f83e772dd05.tar.bz2
nextpnr-eaf824ca73241014a280b1bd787d8f83e772dd05.zip
Use emplace result for get,set of settings
Diffstat (limited to 'common/settings.h')
-rw-r--r--common/settings.h16
1 files changed, 8 insertions, 8 deletions
diff --git a/common/settings.h b/common/settings.h
index 8ced6560..e1f1166a 100644
--- a/common/settings.h
+++ b/common/settings.h
@@ -34,10 +34,11 @@ class Settings
{
try {
IdString id = ctx->id(name);
- if (ctx->settings.find(id) != ctx->settings.end()) {
- return boost::lexical_cast<T>(ctx->settings[id]);
+ auto pair = ctx->settings.emplace(id, std::to_string(defaultValue));
+ if (!pair.second) {
+ return boost::lexical_cast<T>(pair.first->second);
}
- ctx->settings.emplace(id, std::to_string(defaultValue));
+
} catch (boost::bad_lexical_cast &) {
log_error("Problem reading setting %s, using default value\n", name);
}
@@ -47,11 +48,10 @@ class Settings
template <typename T> void set(const char *name, T value)
{
IdString id = ctx->id(name);
- if (ctx->settings.find(id) != ctx->settings.end()) {
- ctx->settings[id] = value;
- return;
- }
- ctx->settings.emplace(id, std::to_string(value));
+ auto pair = ctx->settings.emplace(id, std::to_string(value));
+ if (!pair.second) {
+ ctx->settings[pair.first->first] = value;
+ }
}
private: