From b457b6ec83d724a8d358815135b9a31a1312362d Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Wed, 13 Sep 2017 18:12:03 +0200 Subject: [PATCH] Add a type cache, in case that's important --- src/lib/binary_search.dasl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib/binary_search.dasl b/src/lib/binary_search.dasl index 214b254736..3f06fd61ce 100644 --- a/src/lib/binary_search.dasl +++ b/src/lib/binary_search.dasl @@ -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 @@ -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