diff options
| author | Lioncash <mathew1800@gmail.com> | 2018-07-20 17:12:24 -0400 | 
|---|---|---|
| committer | Lioncash <mathew1800@gmail.com> | 2018-07-20 17:24:06 -0400 | 
| commit | 6279c2dcf43fb3f4749136b92744d0481e4cf0aa (patch) | |
| tree | 5481381f6bd12189653b7ee06ccefe2cee0b9fa1 | |
| parent | 474ec2ee5fd4047babcb24f48385dfde3e5b0421 (diff) | |
param_package: Use std::unordered_map's insert_or_assign instead of map indexing
This avoids a redundant std::string construction if a key doesn't exist
in the map already.
e.g.
data[key] requires constructing a new default instance of the value in
the map (but this is wasteful, since we're already setting something
into the map over top of it).
| -rw-r--r-- | src/common/param_package.cpp | 6 | 
1 files changed, 3 insertions, 3 deletions
diff --git a/src/common/param_package.cpp b/src/common/param_package.cpp index bec58c698..02399b336 100644 --- a/src/common/param_package.cpp +++ b/src/common/param_package.cpp @@ -103,15 +103,15 @@ float ParamPackage::Get(const std::string& key, float default_value) const {  }  void ParamPackage::Set(const std::string& key, const std::string& value) { -    data[key] = value; +    data.insert_or_assign(key, value);  }  void ParamPackage::Set(const std::string& key, int value) { -    data[key] = std::to_string(value); +    data.insert_or_assign(key, std::to_string(value));  }  void ParamPackage::Set(const std::string& key, float value) { -    data[key] = std::to_string(value); +    data.insert_or_assign(key, std::to_string(value));  }  bool ParamPackage::Has(const std::string& key) const {  | 
