mqueue optimizations

This commit is contained in:
Mikayla Fischler
2022-05-06 10:53:12 -04:00
parent d0b2820160
commit 17a46ae642

View File

@ -15,6 +15,9 @@ mqueue.TYPE = TYPE
mqueue.new = function () mqueue.new = function ()
local queue = {} local queue = {}
local insert = table.insert
local remove = table.remove
local length = function () local length = function ()
return #queue return #queue
end end
@ -24,11 +27,11 @@ mqueue.new = function ()
end end
local ready = function () local ready = function ()
return #queue > 0 return #queue ~= 0
end end
local _push = function (qtype, message) local _push = function (qtype, message)
table.insert(queue, { qtype = qtype, message = message }) insert(queue, { qtype = qtype, message = message })
end end
local push_command = function (message) local push_command = function (message)
@ -45,7 +48,7 @@ mqueue.new = function ()
local pop = function () local pop = function ()
if #queue > 0 then if #queue > 0 then
return table.remove(queue, 1) return remove(queue, 1)
else else
return nil return nil
end end