Directly nil check the first element of an array instead of the array's

size when we're only concerned with this single element.
This commit is contained in:
NiLuJe
2022-05-20 21:17:12 +02:00
parent 8914b5e110
commit 4b4d158f32
2 changed files with 6 additions and 4 deletions

View File

@@ -88,7 +88,7 @@ with anonymous functions.
@treturn bool (true if one or more tasks were removed; false otherwise; nil if the task queue is empty).
--]]
function WakeupMgr:removeTasks(epoch, callback)
if #self._task_queue < 1 then return end
if #self._task_queue == 0 then return end
local removed = false
local reschedule = false
@@ -147,7 +147,7 @@ If necessary, the next upcoming task (if any) is scheduled on exit.
@treturn bool (true if we were truly woken up by the scheduled wakeup; false otherwise; nil if there weren't any tasks scheduled).
--]]
function WakeupMgr:wakeupAction(proximity)
if #self._task_queue > 0 then
if self._task_queue[1] then
local task = self._task_queue[1]
if self:validateWakeupAlarmByProximity(task.epoch, proximity) then
task.callback()

View File

@@ -1142,7 +1142,7 @@ end
--]]
function UIManager:getNextTaskTime()
if #self._task_queue > 0 then
if self._task_queue[1] then
return self._task_queue[1].time - time:now()
else
return nil
@@ -1156,10 +1156,12 @@ function UIManager:_checkTasks()
-- task.action may schedule other events
self._task_queue_dirty = false
while true do
if #self._task_queue == 0 then
if not self._task_queue[1] then
-- Nothing to do!
break
end
-- FIXME: Err, the or makes no sense, UIManager:schedule should ensure time & action fields are sane?
-- Either check nothing, or check both time *and* action (which should *never* be nil, unless Greminls, c.f., #9112)
local task_time = self._task_queue[1].time or 0
if task_time <= self._now then
-- remove from table