From ee16095863c61e2d131d3a42bacdaa1720da7cc8 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 29 Jan 2020 22:45:10 -0500 Subject: [PATCH] Withdraws `advance_to_next`; once it has to cope with simultaneous events it stops being faster than `advance`. I could possibly try to deal with those at insertion time, but it'd get messy. --- ClockReceiver/DeferredQueue.hpp | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/ClockReceiver/DeferredQueue.hpp b/ClockReceiver/DeferredQueue.hpp index d061fd7ce..be1c7b01e 100644 --- a/ClockReceiver/DeferredQueue.hpp +++ b/ClockReceiver/DeferredQueue.hpp @@ -22,7 +22,7 @@ template class DeferredQueue { */ void defer(TimeUnit delay, const std::function &action) { // Apply immediately if there's no delay (or a negative delay). - if(delay <= 0) { + if(delay <= TimeUnit(0)) { action(); return; } @@ -74,20 +74,6 @@ template class DeferredQueue { } } - /*! - Advances the queue by @c min(time_until_next_action(),duration) time. - */ - void advance_to_next(TimeUnit duration) { - if(pending_actions_.empty()) return; - - auto front = pending_actions_.front(); - front.delay -= duration; - if(front.delay <= TimeUnit(0)) { - front.action(); - pending_actions_.erase(pending_actions_.begin()); - } - } - private: // The list of deferred actions. struct DeferredAction { @@ -122,11 +108,13 @@ template class DeferredQueuePerformer: public DeferredQueue< while(time_to_next != TimeUnit(-1) && time_to_next <= length) { target_(time_to_next); length -= time_to_next; - DeferredQueue::advance_to_next(time_to_next); + DeferredQueue::advance(time_to_next); } - DeferredQueue::advance_to_next(length); + DeferredQueue::advance(length); target_(length); + + // TODO: optimise this to avoid the multiple std::vector deletes. Find a neat way to expose that solution, maybe? } private: