From 2db1424c8baae17717bf6d0bef807127f3e274ad Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Wed, 16 Dec 2020 14:32:01 +0100 Subject: [PATCH] Avoid unnecessary copy by using a 'const' reference (sonar). --- examples/s4u/io-disk-raw/s4u-io-disk-raw.cpp | 2 +- examples/s4u/synchro-semaphore/s4u-synchro-semaphore.cpp | 2 +- src/instr/instr_paje_header.cpp | 2 +- src/instr/instr_platform.cpp | 2 +- src/surf/network_wifi.cpp | 2 +- src/xbt/xbt_parse_units.cpp | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/s4u/io-disk-raw/s4u-io-disk-raw.cpp b/examples/s4u/io-disk-raw/s4u-io-disk-raw.cpp index d7ebe32c48..84dad4475b 100644 --- a/examples/s4u/io-disk-raw/s4u-io-disk-raw.cpp +++ b/examples/s4u/io-disk-raw/s4u-io-disk-raw.cpp @@ -52,7 +52,7 @@ int main(int argc, char** argv) /* - Display Host properties */ for (auto h : e.get_all_hosts()) { XBT_INFO("*** %s properties ****", h->get_cname()); - for (auto kv : *h->get_properties()) + for (auto const& kv : *h->get_properties()) XBT_INFO(" %s -> %s", kv.first.c_str(), kv.second.c_str()); } diff --git a/examples/s4u/synchro-semaphore/s4u-synchro-semaphore.cpp b/examples/s4u/synchro-semaphore/s4u-synchro-semaphore.cpp index ed5a2b82ed..693a4306d5 100644 --- a/examples/s4u/synchro-semaphore/s4u-synchro-semaphore.cpp +++ b/examples/s4u/synchro-semaphore/s4u-synchro-semaphore.cpp @@ -18,7 +18,7 @@ simgrid::s4u::SemaphorePtr sem_full = simgrid::s4u::Semaphore::create(0); /* in static void producer(const std::vector* args) { - for (auto str : *args) { + for (auto const& str : *args) { sem_empty->acquire(); XBT_INFO("Pushing '%s'", str.c_str()); buffer = str.c_str(); diff --git a/src/instr/instr_paje_header.cpp b/src/instr/instr_paje_header.cpp index 6cd678e4c6..6721856572 100644 --- a/src/instr/instr_paje_header.cpp +++ b/src/instr/instr_paje_header.cpp @@ -19,7 +19,7 @@ void dump_generator_version() tracing_file << "#This file was generated using SimGrid-" << SIMGRID_VERSION_MAJOR << "." << SIMGRID_VERSION_MINOR << "." << SIMGRID_VERSION_PATCH << std::endl; tracing_file << "#["; - for (auto str : simgrid::xbt::cmdline) { + for (auto const& str : simgrid::xbt::cmdline) { tracing_file << str << " "; } tracing_file << "]" << std::endl; diff --git a/src/instr/instr_platform.cpp b/src/instr/instr_platform.cpp index 9237011665..f08514b19e 100644 --- a/src/instr/instr_platform.cpp +++ b/src/instr/instr_platform.cpp @@ -135,7 +135,7 @@ static void recursiveGraphExtraction(const simgrid::s4u::NetZone* netzone, simgr std::map edges; netzone->get_impl()->get_graph(graph, &nodes, &edges); - for (auto elm : edges) { + for (auto const& elm : edges) { const xbt_edge* edge = elm.second; linkContainers(simgrid::instr::Container::by_name(static_cast(edge->src->data)), simgrid::instr::Container::by_name(static_cast(edge->dst->data)), filter); diff --git a/src/surf/network_wifi.cpp b/src/surf/network_wifi.cpp index 05cdc7158f..b0c922db28 100644 --- a/src/surf/network_wifi.cpp +++ b/src/surf/network_wifi.cpp @@ -71,7 +71,7 @@ void NetworkWifiLink::refresh_decay_bandwidths(){ int nSTA = get_host_count(); std::vector new_bandwidths; - for (auto bandwidth : bandwidths_){ + for (auto const& bandwidth : bandwidths_) { // Instantiate decay model relatively to the actual bandwidth double max_bw=bandwidth.peak; double min_bw=bandwidth.peak-(wifi_max_rate_-wifi_min_rate_); diff --git a/src/xbt/xbt_parse_units.cpp b/src/xbt/xbt_parse_units.cpp index 7321a37464..7bdcbf97e7 100644 --- a/src/xbt/xbt_parse_units.cpp +++ b/src/xbt/xbt_parse_units.cpp @@ -120,7 +120,7 @@ std::vector xbt_parse_get_bandwidths(const std::string& filename, int li std::vector bandwidths; std::vector tokens; boost::split(tokens, string, boost::is_any_of(";,")); - for (auto token : tokens) { + for (auto const& token : tokens) { bandwidths.push_back(surf_parse_get_value_with_unit( filename, lineno, token.c_str(), units, entity_kind, name, "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps")); -- 2.20.1