Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Declare local variables inside the if statement.
[simgrid.git] / src / plugins / host_energy.cpp
index ef191bf..fa9578f 100644 (file)
@@ -414,8 +414,7 @@ static void on_action_state_change(simgrid::kernel::resource::CpuAction const& a
     simgrid::s4u::Host* host = cpu->get_iface();
     if (host != nullptr) {
       // If it's a VM, take the corresponding PM
-      const simgrid::s4u::VirtualMachine* vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(host);
-      if (vm) // If it's a VM, take the corresponding PM
+      if (const auto* vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(host))
         host = vm->get_pm();
 
       // Get the host_energy extension for the relevant host
@@ -492,8 +491,7 @@ void sg_host_energy_plugin_init()
   simgrid::s4u::Exec::on_start_cb([](simgrid::s4u::Exec const& activity) {
     if (activity.get_host_number() == 1) { // We only run on one host
       simgrid::s4u::Host* host         = activity.get_host();
-      const simgrid::s4u::VirtualMachine* vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(host);
-      if (vm != nullptr)
+      if (const auto* vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(host))
         host = vm->get_pm();
       xbt_assert(host != nullptr);
       host->extension<HostEnergy>()->update();