From f95d001733819381a8b927263af8925c6cb581c4 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Sun, 19 Nov 2017 20:40:27 +0100 Subject: [PATCH] simplify loops on sets according to https://stackoverflow.com/questions/15433381/performance-of-piter-cont-end-in-for-loop not precomputing the value of end() can even lead to better performance. if agreed by the c++ gurus of SimGrid, this change could be applied to many other places in the code. --- src/surf/network_interface.cpp | 2 +- src/surf/surf_interface.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/surf/network_interface.cpp b/src/surf/network_interface.cpp index 2bbbd86994..fdb7f86259 100644 --- a/src/surf/network_interface.cpp +++ b/src/surf/network_interface.cpp @@ -82,7 +82,7 @@ namespace simgrid { { double minRes = Model::nextOccuringEventFull(now); - for(auto it(getRunningActionSet()->begin()), itend(getRunningActionSet()->end()); it != itend ; it++) { + for (auto it(getRunningActionSet()->begin()); it != getRunningActionSet()->end(); it++) { NetworkAction *action = static_cast(&*it); if (action->latency_ > 0) minRes = (minRes < 0) ? action->latency_ : std::min(minRes, action->latency_); diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index 42b84483a4..df9b6b136b 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -463,7 +463,8 @@ double Model::nextOccuringEventFull(double /*now*/) { maxminSystem_->solve_fun(maxminSystem_); double min = -1; - for (auto it(getRunningActionSet()->begin()), itend(getRunningActionSet()->end()); it != itend ; ++it) { + + for (auto it(getRunningActionSet()->begin()); it != getRunningActionSet()->end(); ++it) { Action *action = &*it; double value = lmm_variable_getvalue(action->getVariable()); if (value > 0) { -- 2.20.1