Skip to content

Commit

Permalink
lwaftr.rangemap: cache and reuse entry types to avoid leak of ctypes
Browse files Browse the repository at this point in the history
  • Loading branch information
eugeneia committed Oct 8, 2019
1 parent daf7bdb commit f7d0f8c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/apps/lwaftr/rangemap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ local function make_entry_type(value_type)
value_type)
end

local entry_type_cache = {}
local function get_entry_type(value_type)
if not entry_type_cache[value_type] then
entry_type_cache[value_type] = make_entry_type(value_type)
end
return entry_type_cache[value_type]
end

local function make_entries_type(entry_type)
return ffi.typeof('$[?]', entry_type)
end
Expand Down Expand Up @@ -63,7 +71,7 @@ end
function RangeMapBuilder.new(value_type)
local builder = {}
builder.value_type = value_type
builder.entry_type = make_entry_type(builder.value_type)
builder.entry_type = get_entry_type(builder.value_type)
builder.type = make_entries_type(builder.entry_type)
builder.equal_fn = make_equal_fn(builder.value_type)
builder.entries = {}
Expand Down

0 comments on commit f7d0f8c

Please sign in to comment.