Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Avoid useless creation of temporary objects with emplace_back (sonar).
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 16 Dec 2020 10:20:00 +0000 (11:20 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 16 Dec 2020 20:49:00 +0000 (21:49 +0100)
src/kernel/resource/profile/Profile.cpp
src/kernel/resource/profile/Profile_test.cpp

index 03b6da0..7e712bd 100644 (file)
@@ -28,10 +28,8 @@ namespace profile {
 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.emplace_back(val);
-  stochastic_event_list.emplace_back(stoval);
+  event_list.emplace_back(0, -1);
+  stochastic_event_list.emplace_back(0, -1);
 }
 Profile::~Profile() = default;
 
index f7e2abd..fbdb0bb 100644 (file)
@@ -162,9 +162,8 @@ TEST_CASE("kernel::profile: Resource profiles, defining the external load", "ker
                                                                                    "DET 0 UNIF 10 20");
 
     std::vector<simgrid::kernel::profile::StochasticDatedValue> want;
-    want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(0, -1)); // The initial fake event
-    want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(Distribution::DET, {0},
-                                                                     Distribution::UNIF, {10, 20}));
+    want.emplace_back(0, -1); // The initial fake event
+    want.emplace_back(Distribution::DET, std::vector<double>{0}, Distribution::UNIF, std::vector<double>{10, 20});
 
     REQUIRE(want == got);
   }
@@ -179,15 +178,11 @@ TEST_CASE("kernel::profile: Resource profiles, defining the external load", "ker
                                                                                    "DET 5 UNIF 5 25");
 
     std::vector<simgrid::kernel::profile::StochasticDatedValue> want;
-    want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(0, -1));
-    want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(Distribution::DET, {0},
-                                                                     Distribution::DET, {4}));
-    want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(Distribution::NORM, {25, 10},
-                                                                     Distribution::DET, {3}));
-    want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(Distribution::UNIF, {10, 20},
-                                                                     Distribution::NORM, {25, 10}));
-    want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(Distribution::DET, {5},
-                                                                     Distribution::UNIF, {5, 25}));
+    want.emplace_back(0, -1);
+    want.emplace_back(Distribution::DET, std::vector<double>{0}, Distribution::DET, std::vector<double>{4});
+    want.emplace_back(Distribution::NORM, std::vector<double>{25, 10}, Distribution::DET, std::vector<double>{3});
+    want.emplace_back(Distribution::UNIF, std::vector<double>{10, 20}, Distribution::NORM, std::vector<double>{25, 10});
+    want.emplace_back(Distribution::DET, std::vector<double>{5}, Distribution::UNIF, std::vector<double>{5, 25});
 
     REQUIRE(want == got);
   }
@@ -202,8 +197,8 @@ TEST_CASE("kernel::profile: Resource profiles, defining the external load", "ker
 
     std::vector<simgrid::kernel::profile::DatedValue> want;
     // The following values were drawn using the XBT_RNG_xbt method /outside/ the testcase.
-    want.emplace_back(simgrid::kernel::profile::DatedValue(0, 19.29616086867082813683));
-    want.emplace_back(simgrid::kernel::profile::DatedValue(2.32719992449416279712, 20.16807234800742065772));
+    want.emplace_back(0, 19.29616086867082813683);
+    want.emplace_back(2.32719992449416279712, 20.16807234800742065772);
 
     REQUIRE(want == got);
   }
@@ -220,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<simgrid::kernel::profile::DatedValue> want;
-    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));
+    want.emplace_back(0, 19.29616086867082813683);
+    want.emplace_back(2.32719992449416279712, 20.16807234800742065772);
+    want.emplace_back(3.51111873684917075167, 0);
+    want.emplace_back(3.51111873684917075167, 10.39759496468994726115);
 
     REQUIRE(want == got);
   }