Skip to content

Commit

Permalink
Add a type cache, in case that's important
Browse files Browse the repository at this point in the history
  • Loading branch information
wingo authored and alexandergall committed Mar 15, 2018
1 parent 907ce81 commit b457b6e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/lib/binary_search.dasl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ local function assemble (name, prototype, generator)
return ffi.cast(prototype, mcode)
end

local ffi_type_cache = {}

function gen(count, entry_type)
local function gen_binary_search(Dst)
if count == 1 then
Expand Down Expand Up @@ -80,8 +82,11 @@ function gen(count, entry_type)
| mov rax, rdi
| ret
end
return assemble("binary_search_"..count,
ffi.typeof("$*(*)($*, uint32_t)", entry_type, entry_type),
if not ffi_type_cache[entry_type] then
ffi_type_cache[entry_type] = ffi.typeof(
"$*(*)($*, uint32_t)", entry_type, entry_type)
end
return assemble("binary_search_"..count, ffi_type_cache[entry_type],
gen_binary_search)
end

Expand Down

0 comments on commit b457b6e

Please sign in to comment.