From 143994880edea4c404a0ef92d665ed68f4a0125b Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Thu, 14 Feb 2019 13:45:52 +0100 Subject: [PATCH 1/1] More std::string parameters. --- src/kernel/activity/SleepImpl.hpp | 2 +- src/xbt/config.cpp | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/kernel/activity/SleepImpl.hpp b/src/kernel/activity/SleepImpl.hpp index eab5d22de5..a98198fd36 100644 --- a/src/kernel/activity/SleepImpl.hpp +++ b/src/kernel/activity/SleepImpl.hpp @@ -17,7 +17,7 @@ class XBT_PUBLIC SleepImpl : public ActivityImpl { ~SleepImpl() override; public: - explicit SleepImpl(std::string name, s4u::Host* host) : ActivityImpl(name), host_(host) {} + explicit SleepImpl(std::string name, s4u::Host* host) : ActivityImpl(std::move(name)), host_(host) {} void post() override; SleepImpl* start(double duration); diff --git a/src/xbt/config.cpp b/src/xbt/config.cpp index f8aee5d888..6d7db52f0d 100644 --- a/src/xbt/config.cpp +++ b/src/xbt/config.cpp @@ -143,8 +143,11 @@ public: /* Callback */ xbt_cfg_cb_t old_callback = nullptr; - ConfigurationElement(std::string key, std::string desc) : key(key), desc(desc) {} - ConfigurationElement(std::string key, std::string desc, xbt_cfg_cb_t cb) : key(key), desc(desc), old_callback(cb) {} + ConfigurationElement(std::string key, std::string desc) : key(std::move(key)), desc(std::move(desc)) {} + ConfigurationElement(std::string key, std::string desc, xbt_cfg_cb_t cb) + : key(std::move(key)), desc(std::move(desc)), old_callback(cb) + { + } virtual ~ConfigurationElement() = default; @@ -182,13 +185,13 @@ private: public: TypedConfigurationElement(std::string key, std::string desc, T value = T()) - : ConfigurationElement(key, desc), content(std::move(value)) + : ConfigurationElement(std::move(key), std::move(desc)), content(std::move(value)) {} TypedConfigurationElement(std::string key, std::string desc, T value, xbt_cfg_cb_t cb) - : ConfigurationElement(key, desc, cb), content(std::move(value)) + : ConfigurationElement(std::move(key), std::move(desc), cb), content(std::move(value)) {} TypedConfigurationElement(std::string key, std::string desc, T value, std::function callback) - : ConfigurationElement(key, desc), content(std::move(value)), callback(std::move(callback)) + : ConfigurationElement(std::move(key), std::move(desc)), content(std::move(value)), callback(std::move(callback)) {} ~TypedConfigurationElement() = default; @@ -262,8 +265,8 @@ public: Config(Config const&) = delete; Config& operator=(Config const&) = delete; - ConfigurationElement& operator[](std::string name); - void alias(std::string realname, std::string aliasname); + ConfigurationElement& operator[](const std::string& name); + void alias(const std::string& realname, const std::string& aliasname); template simgrid::config::TypedConfigurationElement* register_option(const std::string& name, A&&... a) @@ -284,7 +287,7 @@ public: void help(); protected: - ConfigurationElement* get_dict_element(std::string name); + ConfigurationElement* get_dict_element(const std::string& name); }; Config::Config() @@ -298,7 +301,7 @@ Config::~Config() delete elm.second; } -inline ConfigurationElement* Config::get_dict_element(std::string name) +inline ConfigurationElement* Config::get_dict_element(const std::string& name) { auto opt = options.find(name); if (opt != options.end()) { @@ -316,12 +319,12 @@ inline ConfigurationElement* Config::get_dict_element(std::string name) } } -inline ConfigurationElement& Config::operator[](std::string name) +inline ConfigurationElement& Config::operator[](const std::string& name) { return *(get_dict_element(name)); } -void Config::alias(std::string realname, std::string aliasname) +void Config::alias(const std::string& realname, const std::string& aliasname) { xbt_assert(aliases.find(aliasname) == aliases.end(), "Alias '%s' already.", aliasname.c_str()); ConfigurationElement* element = this->get_dict_element(realname); -- 2.20.1