summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2013-11-18 17:57:32 -0500
committerShadowNinja <shadowninja@minetest.net>2013-11-18 17:57:32 -0500
commitf98312fe10b168eb4ba40c567075661e2f0060bf (patch)
treeee8c11d95fe366d19d1dfd6008195cef907df368
parent810a706e5fb54b43f3349504c33b26e672f9a8af (diff)
Optimize area and index finding
-rw-r--r--internal.lua12
1 files changed, 8 insertions, 4 deletions
diff --git a/internal.lua b/internal.lua
index 3c4212b..e57cfd8 100644
--- a/internal.lua
+++ b/internal.lua
@@ -158,16 +158,20 @@ end
-- Returns a area given it's identifier
function areas:getAreaById(id)
- for _, area in pairs(self.areas) do
- if area.id == id then return area end
+ if not self.areas[id] then
+ return nil
end
+ assert(self.areas[id].id == id)
+ return self.areas[id]
end
-- Returns a table index for an area given it's identifier
function areas:getIndexById(id)
- for i, area in pairs(self.areas) do
- if area.id == id then return i end
+ if not self.areas[id] then
+ return nil
end
+ assert(self.areas[id].id == id)
+ return id
end
-- Re-order areas in table by their identifiers