From c972ddd5a74b83c183357f707e7dfba87d48e750 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Thu, 10 Jun 2021 10:19:38 +0200 Subject: [PATCH] Use empty() to check for container emptiness. --- examples/deprecated/java/app/bittorrent/Peer.java | 2 +- src/kernel/resource/profile/Profile.cpp | 2 +- src/s4u/s4u_Actor.cpp | 2 +- src/smpi/internals/smpi_deployment.cpp | 10 +++++----- src/surf/cpu_interface.cpp | 2 +- teshsuite/surf/surf_usage2/surf_usage2.cpp | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/deprecated/java/app/bittorrent/Peer.java b/examples/deprecated/java/app/bittorrent/Peer.java index 83f36cc234..3bd30bf8d7 100644 --- a/examples/deprecated/java/app/bittorrent/Peer.java +++ b/examples/deprecated/java/app/bittorrent/Peer.java @@ -395,7 +395,7 @@ public class Peer extends Process { // Update the list of current choked and unchoked peers, using the choke algorithm private void updateChokedPeers() { round = (round + 1) % 3; - if (peers.size() == 0) { + if (peers.isEmpty()) { return; } //remove a peer from the list diff --git a/src/kernel/resource/profile/Profile.cpp b/src/kernel/resource/profile/Profile.cpp index 7174d926ac..b6167c491d 100644 --- a/src/kernel/resource/profile/Profile.cpp +++ b/src/kernel/resource/profile/Profile.cpp @@ -129,7 +129,7 @@ Profile* Profile::from_string(const std::string& name, const std::string& input, std::vector splittedval((std::istream_iterator(iss)), std::istream_iterator()); - xbt_assert(splittedval.size() > 0, "Invalid profile line"); + xbt_assert(not splittedval.empty(), "Invalid profile line"); if (splittedval[0] == "DET") { stochevent.date_law = Distribution::DET; diff --git a/src/s4u/s4u_Actor.cpp b/src/s4u/s4u_Actor.cpp index bb548f0739..5a67ebda72 100644 --- a/src/s4u/s4u_Actor.cpp +++ b/src/s4u/s4u_Actor.cpp @@ -387,7 +387,7 @@ ExecPtr exec_init(double flops_amount) ExecPtr exec_init(const std::vector& hosts, const std::vector& flops_amounts, const std::vector& bytes_amounts) { - xbt_assert(hosts.size() > 0, "Your parallel executions must span over at least one host."); + xbt_assert(not hosts.empty(), "Your parallel executions must span over at least one host."); xbt_assert(hosts.size() == flops_amounts.size() || flops_amounts.empty(), "Host count (%zu) does not match flops_amount count (%zu).", hosts.size(), flops_amounts.size()); xbt_assert(hosts.size() * hosts.size() == bytes_amounts.size() || bytes_amounts.empty(), diff --git a/src/smpi/internals/smpi_deployment.cpp b/src/smpi/internals/smpi_deployment.cpp index f2721dba2d..93c7e61443 100644 --- a/src/smpi/internals/smpi_deployment.cpp +++ b/src/smpi/internals/smpi_deployment.cpp @@ -115,10 +115,10 @@ static std::vector smpi_get_hosts(simgrid::s4u::Engine* e, xbt_assert(in, "smpirun: Cannot open the host file: %s", hostfile.c_str()); std::string str; while (std::getline(in, str)) { - if (str.size() > 0) + if (not str.empty()) hosts.emplace_back(e->host_by_name(str)); } - xbt_assert(hosts.size(), "smpirun: the hostfile '%s' is empty", hostfile.c_str()); + xbt_assert(not hosts.empty(), "smpirun: the hostfile '%s' is empty", hostfile.c_str()); return hosts; } @@ -133,7 +133,7 @@ static std::vector smpi_read_replay(const std::string& replayfile) xbt_assert(in, "smpirun: Cannot open the replay file: %s", replayfile.c_str()); std::string str; while (std::getline(in, str)) { - if (str.size() > 0) + if (not str.empty()) replay.emplace_back(str); } @@ -146,7 +146,7 @@ static std::vector smpi_deployment_get_args(int rank_id, const std: { std::vector args{std::to_string(rank_id)}; // pass arguments to process only if not a replay execution - if (replay.size() == 0) { + if (replay.empty()) { for (int i = 0; i < argc; i++) { args.push_back(argv[i]); } @@ -190,7 +190,7 @@ int smpi_deployment_smpirun(simgrid::s4u::Engine* e, const std::string& hostfile } actor->set_property("instance_id", "smpirun"); actor->set_property("rank", rank_id); - if (replay.size() > 0) + if (not replay.empty()) actor->set_property("smpi_replay", "true"); /* shared trace file, set it to rank 0 */ if (i == 0 && replay.size() == 1) diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index 24f37a891c..8a9a5c1b11 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -82,7 +82,7 @@ CpuImpl* CpuImpl::set_pstate(int pstate_index) CpuImpl* CpuImpl::set_pstate_speed(const std::vector& speed_per_state) { - xbt_assert(speed_per_state.size() > 0, "CPU %s: processor speed vector cannot be empty", get_cname()); + xbt_assert(not speed_per_state.empty(), "CPU %s: processor speed vector cannot be empty", get_cname()); xbt_assert(not is_sealed(), "CPU %s: processor speed cannot be changed once CPU has been sealed", get_cname()); speed_per_pstate_ = speed_per_state; speed_.peak = speed_per_pstate_.front(); diff --git a/teshsuite/surf/surf_usage2/surf_usage2.cpp b/teshsuite/surf/surf_usage2/surf_usage2.cpp index c79d19bb69..e52a0e4b03 100644 --- a/teshsuite/surf/surf_usage2/surf_usage2.cpp +++ b/teshsuite/surf/surf_usage2/surf_usage2.cpp @@ -51,7 +51,7 @@ int main(int argc, char** argv) XBT_INFO("Next Event : %g", now); for (auto const& model : simgrid::kernel::EngineImpl::get_instance()->get_all_models()) { - if (model->get_started_action_set()->size() != 0) { + if (not model->get_started_action_set()->empty()) { XBT_DEBUG("\t Running that model"); running = 1; } -- 2.20.1