forked from nalc/areas
Optimize area and index finding
This commit is contained in:
parent
810a706e5f
commit
f98312fe10
12
internal.lua
12
internal.lua
@ -158,16 +158,20 @@ end
|
|||||||
|
|
||||||
-- Returns a area given it's identifier
|
-- Returns a area given it's identifier
|
||||||
function areas:getAreaById(id)
|
function areas:getAreaById(id)
|
||||||
for _, area in pairs(self.areas) do
|
if not self.areas[id] then
|
||||||
if area.id == id then return area end
|
return nil
|
||||||
end
|
end
|
||||||
|
assert(self.areas[id].id == id)
|
||||||
|
return self.areas[id]
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Returns a table index for an area given it's identifier
|
-- Returns a table index for an area given it's identifier
|
||||||
function areas:getIndexById(id)
|
function areas:getIndexById(id)
|
||||||
for i, area in pairs(self.areas) do
|
if not self.areas[id] then
|
||||||
if area.id == id then return i end
|
return nil
|
||||||
end
|
end
|
||||||
|
assert(self.areas[id].id == id)
|
||||||
|
return id
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Re-order areas in table by their identifiers
|
-- Re-order areas in table by their identifiers
|
||||||
|
Loading…
Reference in New Issue
Block a user