From 13b9ee09ee1a8d2423baa0f4f84f5509e389023a Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Sun, 13 Jan 2013 12:23:06 +0100 Subject: Minor optimization of handling the timers --- src/FbTk/Timer.cc | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/FbTk/Timer.cc b/src/FbTk/Timer.cc index dd736dd..eff3af4 100644 --- a/src/FbTk/Timer.cc +++ b/src/FbTk/Timer.cc @@ -200,31 +200,31 @@ void Timer::updateTimers(int fd) { // way. to avoid problems such as infinite loops we save the current // (ordered) list of timers into a list and work on it. - ssize_t i; - const ssize_t ts = s_timerlist.size(); - std::vector timers; + static std::vector timeouts; - timers.reserve(ts); + now = FbTime::now(); for (it = s_timerlist.begin(); it != s_timerlist.end(); ++it ) { - timers.push_back(*it); + if (now < (*it)->getEndTime()) { + break; + } + timeouts.push_back(*it); } - now = FbTime::now(); + size_t i; + const size_t ts = timeouts.size(); for (i = 0; i < ts; ++i) { - FbTk::Timer* t = timers[i]; + FbTk::Timer& t = *timeouts[i]; - if (now < t->getEndTime()) { - break; - } + t.fireTimeout(); + t.stop(); - t->fireTimeout(); - t->stop(); - - if (! t->doOnce()) { // restart the current timer - t->start(); + if (! t.doOnce()) { // restart the current timer + t.start(); } } + + timeouts.clear(); } -- cgit v0.11.2