From 656d1d84782545d13a71b9dbf956ef2c69ec3af6 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Sun, 10 Mar 2019 15:46:37 +0100 Subject: [PATCH] Constify. --- include/simgrid/kernel/resource/Action.hpp | 2 +- include/xbt/config.hpp | 2 +- include/xbt/file.hpp | 2 +- src/instr/instr_paje_containers.hpp | 2 +- src/instr/instr_paje_events.cpp | 9 +++++---- src/instr/instr_paje_types.hpp | 2 +- src/instr/instr_private.hpp | 2 +- 7 files changed, 11 insertions(+), 10 deletions(-) diff --git a/include/simgrid/kernel/resource/Action.hpp b/include/simgrid/kernel/resource/Action.hpp index 6ce0e7cc7f..0acd6b51fb 100644 --- a/include/simgrid/kernel/resource/Action.hpp +++ b/include/simgrid/kernel/resource/Action.hpp @@ -180,7 +180,7 @@ public: virtual void set_max_duration(double duration); /** @brief Get the tracing category associated to the current action */ - std::string get_category() const { return category_; } + const std::string& get_category() const { return category_; } /** @brief Set the tracing category of the current Action */ void set_category(std::string category) { category_ = std::move(category); } diff --git a/include/xbt/config.hpp b/include/xbt/config.hpp index fed58c9410..9bb3619262 100644 --- a/include/xbt/config.hpp +++ b/include/xbt/config.hpp @@ -278,7 +278,7 @@ public: T& get() { return value_; } T const& get() const { return value_; } - std::string get_name() const { return name_; } + const std::string& get_name() const { return name_; } // Implicit conversion to the underlying type: operator T&() { return value_; } operator T const&() const{ return value_; } diff --git a/include/xbt/file.hpp b/include/xbt/file.hpp index 91c285b99b..4ef6c04df3 100644 --- a/include/xbt/file.hpp +++ b/include/xbt/file.hpp @@ -22,7 +22,7 @@ public: explicit Path(std::string path): path_(std::move(path)) {} /** @brief Returns the full path name */ - std::string get_name() { return path_; } + const std::string& get_name() const { return path_; } /** @brief Returns the directory component of a path (reimplementation of POSIX dirname) */ std::string get_dir_name(); /** @brief Returns the file component of a path (reimplementation of POSIX basename) */ diff --git a/src/instr/instr_paje_containers.hpp b/src/instr/instr_paje_containers.hpp index da60460031..0e49398761 100644 --- a/src/instr/instr_paje_containers.hpp +++ b/src/instr/instr_paje_containers.hpp @@ -32,7 +32,7 @@ public: static Container* by_name_or_null(const std::string& name); static Container* by_name(const std::string& name); - std::string get_name() { return name_; } + const std::string& get_name() const { return name_; } const char* get_cname() { return name_.c_str(); } long long int get_id() { return id_; } void remove_from_parent(); diff --git a/src/instr/instr_paje_events.cpp b/src/instr/instr_paje_events.cpp index 3ee840aaed..0870bf097f 100644 --- a/src/instr/instr_paje_events.cpp +++ b/src/instr/instr_paje_events.cpp @@ -107,12 +107,13 @@ void StateEvent::print() /* Unimplemented calls are: WAITANY, SENDRECV, SCAN, EXSCAN, SSEND, and ISSEND. */ // FIXME: dirty extract "rank-" from the name, as we want the bare process id here - if (get_container()->get_name().find("rank-") != 0) + if (get_container()->get_name().find("rank-") != 0) { stream_ << get_container()->get_name() << " " << extra_->print(); - else + } else { /* Subtract -1 because this is the process id and we transform it to the rank id */ - stream_ << stoi(get_container()->get_name().erase(0, 5)) - 1 << " " << extra_->print(); - + std::string container_name(get_container()->get_name()); + stream_ << stoi(container_name.erase(0, 5)) - 1 << " " << extra_->print(); + } *tracing_files.at(get_container()) << stream_.str() << std::endl; } else { THROW_IMPOSSIBLE; diff --git a/src/instr/instr_paje_types.hpp b/src/instr/instr_paje_types.hpp index 21a440a45e..47ed87cef7 100644 --- a/src/instr/instr_paje_types.hpp +++ b/src/instr/instr_paje_types.hpp @@ -30,7 +30,7 @@ public: Type(std::string name, std::string alias, std::string color, Type* father); virtual ~Type(); - std::string get_name() { return name_; } + const std::string& get_name() const { return name_; } const char* get_cname() { return name_.c_str(); } long long int get_id() { return id_; } bool is_colored() { return not color_.empty(); } diff --git a/src/instr/instr_private.hpp b/src/instr/instr_private.hpp index e34187ce6d..ca0119cc0b 100644 --- a/src/instr/instr_private.hpp +++ b/src/instr/instr_private.hpp @@ -95,7 +95,7 @@ public: virtual ~TIData() {} - std::string getName() { return name_; } + const std::string& getName() const { return name_; } double getAmount() { return amount_; } virtual std::string print() = 0; virtual std::string display_size() = 0; -- 2.20.1