From 2d4cd1c5cac5d5ee6d359000878a5e9a39aac51f Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Fri, 23 Oct 2020 14:37:52 +0200 Subject: [PATCH] Polishing last merged bits. --- src/kernel/resource/profile/Profile.cpp | 19 +++++----- src/kernel/resource/profile/Profile_test.cpp | 36 +++++++++---------- .../resource/profile/StochasticDatedValue.hpp | 3 +- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/kernel/resource/profile/Profile.cpp b/src/kernel/resource/profile/Profile.cpp index 478c0c466a..587a063a67 100644 --- a/src/kernel/resource/profile/Profile.cpp +++ b/src/kernel/resource/profile/Profile.cpp @@ -29,8 +29,8 @@ Profile::Profile() /* Add the first fake event storing the time at which the trace begins */ DatedValue val(0, -1); StochasticDatedValue stoval(0, -1); - event_list.push_back(val); - stochastic_event_list.push_back(stoval); + event_list.emplace_back(val); + stochastic_event_list.emplace_back(stoval); } Profile::~Profile() = default; @@ -48,8 +48,8 @@ Event* Profile::schedule(FutureEvtSet* fes, resource::Resource* resource) fes_ = fes; fes_->add_event(0.0 /* start time */, event); - if (stochastic > 0) { - xbt_assert((event->idx < stochastic_event_list.size()), "Your profile should have at least one stochastic event!"); + if (stochastic) { + xbt_assert(event->idx < stochastic_event_list.size(), "Your profile should have at least one stochastic event!"); futureDV = stochastic_event_list.at(event->idx).get_datedvalue(); } @@ -78,15 +78,14 @@ DatedValue Profile::next(Event* event) DatedValue dateVal = futureDV; if (event->idx < stochastic_event_list.size() - 1) { event->idx++; - } else if (stochasticloop > 0) { /* We have reached the last element and we have to loop. */ + } else if (stochasticloop) { /* We have reached the last element and we have to loop. */ event->idx = 1; } else { event->free_me = true; /* We have reached the last element, but we don't need to loop. */ } - if (event->free_me == false) { // In the case there is an element, we draw the next event - StochasticDatedValue stodateVal = stochastic_event_list.at(event->idx); - futureDV = stochastic_event_list.at(event->idx).get_datedvalue(); + if (not event->free_me) { // In the case there is an element, we draw the next event + futureDV = stochastic_event_list.at(event->idx).get_datedvalue(); fes_->add_event(event_date + futureDV.date_, event); } return dateVal; @@ -183,7 +182,7 @@ Profile* Profile::from_string(const std::string& name, const std::string& input, stochevent.value_params = {std::atof(splittedval[i + 1].c_str()), std::atof(splittedval[i + 2].c_str())}; } - profile->stochastic_event_list.push_back(stochevent); + profile->stochastic_event_list.emplace_back(stochevent); } else { XBT_ATTRIB_UNUSED int res = sscanf(val.c_str(), "%lg %lg\n", &event.date_, &event.value_); xbt_assert(res == 2, "%s:%d: Syntax error in trace\n%s", name.c_str(), linecount, input.c_str()); @@ -193,7 +192,7 @@ Profile* Profile::from_string(const std::string& name, const std::string& input, last_event->date_, event.date_, input.c_str()); last_event->date_ = event.date_ - last_event->date_; - profile->event_list.push_back(event); + profile->event_list.emplace_back(event); last_event = &(profile->event_list.back()); } } diff --git a/src/kernel/resource/profile/Profile_test.cpp b/src/kernel/resource/profile/Profile_test.cpp index 8bb95a8412..0d2d72bfa1 100644 --- a/src/kernel/resource/profile/Profile_test.cpp +++ b/src/kernel/resource/profile/Profile_test.cpp @@ -158,9 +158,9 @@ TEST_CASE("kernel::profile: Resource profiles, defining the external load", "ker "DET 0 UNIF 10 20"); std::vector want; - want.push_back(simgrid::kernel::profile::StochasticDatedValue(0, -1)); // The initial fake event - want.push_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Det, {0}, - simgrid::kernel::profile::Dist_Unif, {10, 20})); + want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(0, -1)); // The initial fake event + want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Det, {0}, + simgrid::kernel::profile::Dist_Unif, {10, 20})); REQUIRE(want == got); } @@ -174,15 +174,15 @@ TEST_CASE("kernel::profile: Resource profiles, defining the external load", "ker "DET 5 UNIF 5 25"); std::vector want; - want.push_back(simgrid::kernel::profile::StochasticDatedValue(0, -1)); - want.push_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Det, {0}, - simgrid::kernel::profile::Dist_Det, {4})); - want.push_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Norm, {25, 10}, - simgrid::kernel::profile::Dist_Det, {3})); - want.push_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Unif, {10, 20}, - simgrid::kernel::profile::Dist_Norm, {25, 10})); - want.push_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Det, {5}, - simgrid::kernel::profile::Dist_Unif, {5, 25})); + want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(0, -1)); + want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Det, {0}, + simgrid::kernel::profile::Dist_Det, {4})); + want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Norm, {25, 10}, + simgrid::kernel::profile::Dist_Det, {3})); + want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Unif, {10, 20}, + simgrid::kernel::profile::Dist_Norm, {25, 10})); + want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Det, {5}, + simgrid::kernel::profile::Dist_Unif, {5, 25})); REQUIRE(want == got); } @@ -197,8 +197,8 @@ TEST_CASE("kernel::profile: Resource profiles, defining the external load", "ker std::vector want; // The following values were drawn using the XBT_RNG_xbt method /outside/ the testcase. - want.push_back(simgrid::kernel::profile::DatedValue(0, 19.29616086867082813683)); - want.push_back(simgrid::kernel::profile::DatedValue(2.32719992449416279712, 20.16807234800742065772)); + want.emplace_back(simgrid::kernel::profile::DatedValue(0, 19.29616086867082813683)); + want.emplace_back(simgrid::kernel::profile::DatedValue(2.32719992449416279712, 20.16807234800742065772)); REQUIRE(want == got); } @@ -215,10 +215,10 @@ TEST_CASE("kernel::profile: Resource profiles, defining the external load", "ker // In this case, the main use of the last stochastic event is to set when the first event takes place. std::vector want; - want.push_back(simgrid::kernel::profile::DatedValue(0, 19.29616086867082813683)); - want.push_back(simgrid::kernel::profile::DatedValue(2.32719992449416279712, 20.16807234800742065772)); - want.push_back(simgrid::kernel::profile::DatedValue(3.51111873684917075167, 0)); - want.push_back(simgrid::kernel::profile::DatedValue(3.51111873684917075167, 10.39759496468994726115)); + want.emplace_back(simgrid::kernel::profile::DatedValue(0, 19.29616086867082813683)); + want.emplace_back(simgrid::kernel::profile::DatedValue(2.32719992449416279712, 20.16807234800742065772)); + want.emplace_back(simgrid::kernel::profile::DatedValue(3.51111873684917075167, 0)); + want.emplace_back(simgrid::kernel::profile::DatedValue(3.51111873684917075167, 10.39759496468994726115)); REQUIRE(want == got); } diff --git a/src/kernel/resource/profile/StochasticDatedValue.hpp b/src/kernel/resource/profile/StochasticDatedValue.hpp index d0b29b229a..29bc98916f 100644 --- a/src/kernel/resource/profile/StochasticDatedValue.hpp +++ b/src/kernel/resource/profile/StochasticDatedValue.hpp @@ -30,7 +30,8 @@ public: : date_law(Dist_Det), date_params({d}), value_law(Dist_Det), value_params({v}) { } - explicit StochasticDatedValue(Distribution dl, std::vector dp, Distribution vl, std::vector vp) + explicit StochasticDatedValue(Distribution dl, const std::vector& dp, Distribution vl, + const std::vector& vp) : date_law(dl), date_params(dp), value_law(vl), value_params(vp) { } -- 2.20.1