mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
mqueue optimizations
This commit is contained in:
@ -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
|
||||||
|
Reference in New Issue
Block a user