Minor optimization of handling the timers

This commit is contained in:
Mathias Gumz 2013-01-13 12:23:06 +01:00
parent 4d307dcd10
commit 13b9ee09ee

View file

@ -200,31 +200,31 @@ void Timer::updateTimers(int fd) {
// way. to avoid problems such as infinite loops we save the current // way. to avoid problems such as infinite loops we save the current
// (ordered) list of timers into a list and work on it. // (ordered) list of timers into a list and work on it.
ssize_t i; static std::vector<FbTk::Timer*> timeouts;
const ssize_t ts = s_timerlist.size();
std::vector<FbTk::Timer*> timers;
timers.reserve(ts);
for (it = s_timerlist.begin(); it != s_timerlist.end(); ++it ) {
timers.push_back(*it);
}
now = FbTime::now(); now = FbTime::now();
for (i = 0; i < ts; ++i) { for (it = s_timerlist.begin(); it != s_timerlist.end(); ++it ) {
if (now < (*it)->getEndTime()) {
FbTk::Timer* t = timers[i];
if (now < t->getEndTime()) {
break; break;
} }
timeouts.push_back(*it);
}
t->fireTimeout(); size_t i;
t->stop(); const size_t ts = timeouts.size();
for (i = 0; i < ts; ++i) {
if (! t->doOnce()) { // restart the current timer FbTk::Timer& t = *timeouts[i];
t->start();
t.fireTimeout();
t.stop();
if (! t.doOnce()) { // restart the current timer
t.start();
} }
} }
timeouts.clear();
} }