From: Frederic Suter Date: Sun, 19 Nov 2017 19:40:27 +0000 (+0100) Subject: simplify loops on sets X-Git-Tag: v3.18~242^2~8 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/f95d001733819381a8b927263af8925c6cb581c4?ds=sidebyside 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. --- 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) {