mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:47:34 +00:00
LibCore: Exit get_next_timer_expiration() sooner if possible
If we find a timer that needs to be fired immediately, we can stop looking through the remaining timers. This significantly reduces time spent in get_next_timer_expiration() on ACID3. Of course, with a better data structure, we could reduce time spent further. I've left a FIXME about that.
This commit is contained in:
parent
06948df393
commit
1a323ec8d4
1 changed files with 5 additions and 0 deletions
|
@ -793,6 +793,7 @@ void EventLoopTimer::reload(const Time& now)
|
||||||
|
|
||||||
Optional<Time> EventLoop::get_next_timer_expiration()
|
Optional<Time> EventLoop::get_next_timer_expiration()
|
||||||
{
|
{
|
||||||
|
auto now = Time::now_monotonic_coarse();
|
||||||
Optional<Time> soonest {};
|
Optional<Time> soonest {};
|
||||||
for (auto& it : *s_timers) {
|
for (auto& it : *s_timers) {
|
||||||
auto& fire_time = it.value->fire_time;
|
auto& fire_time = it.value->fire_time;
|
||||||
|
@ -801,6 +802,10 @@ Optional<Time> EventLoop::get_next_timer_expiration()
|
||||||
&& owner && !owner->is_visible_for_timer_purposes()) {
|
&& owner && !owner->is_visible_for_timer_purposes()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// OPTIMIZATION: If we have a timer that needs to fire right away, we can stop looking here.
|
||||||
|
// FIXME: This whole operation could be O(1) with a better data structure.
|
||||||
|
if (fire_time < now)
|
||||||
|
return now;
|
||||||
if (!soonest.has_value() || fire_time < soonest.value())
|
if (!soonest.has_value() || fire_time < soonest.value())
|
||||||
soonest = fire_time;
|
soonest = fire_time;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue