mirror of
https://github.com/minetest-mods/areas.git
synced 2024-12-25 02:00:40 +01:00
Stop reusing holes in areas IDs
This eliminates the need of iterating the whole list for every protection operations. Note that the highest index isn't cached, i.e. the first or few (if there are many holes) operations would still suffer from the lag.
This commit is contained in:
parent
d2b227eca6
commit
ec77a57f42
16
internal.lua
16
internal.lua
@ -83,19 +83,19 @@ function areas:populateStore()
|
||||
self.store_ids = store_ids
|
||||
end
|
||||
|
||||
-- Finds the first usable index in a table
|
||||
-- Eg: {[1]=false,[4]=true} -> 2
|
||||
local function findFirstUnusedIndex(t)
|
||||
local i = 0
|
||||
repeat i = i + 1
|
||||
until t[i] == nil
|
||||
return i
|
||||
-- Guarentees returning an unused index in areas.areas
|
||||
local index_cache = 0
|
||||
local function findFirstUnusedIndex()
|
||||
local t = areas.areas
|
||||
repeat index_cache = index_cache + 1
|
||||
until t[index_cache] == nil
|
||||
return index_cache
|
||||
end
|
||||
|
||||
--- Add an area.
|
||||
-- @return The new area's ID.
|
||||
function areas:add(owner, name, pos1, pos2, parent)
|
||||
local id = findFirstUnusedIndex(self.areas)
|
||||
local id = findFirstUnusedIndex()
|
||||
self.areas[id] = {
|
||||
name = name,
|
||||
pos1 = pos1,
|
||||
|
Loading…
Reference in New Issue
Block a user