diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua index cd132bab206e6d995cf81141ac83d271cb54325d..f8127d8666c8c74fd1596e079ae7400e394762a9 100644 --- a/src/box/lua/schema.lua +++ b/src/box/lua/schema.lua @@ -9,6 +9,12 @@ local internal = require('box.internal') local builtin = ffi.C +-- performance fixup for hot functions +local tuple_encode = box.tuple.encode +local tuple_bless = box.tuple.bless +local is_tuple = box.tuple.is +assert(tuple_encode ~= nil and tuple_bless ~= nil and is_tuple ~= nil) + ffi.cdef[[ struct space *space_by_id(uint32_t id); void space_run_triggers(struct space *space, bool yesno); @@ -576,7 +582,7 @@ local ptuple = ffi.new('box_tuple_t *[1]') local function keify(key) if key == nil then return {} - elseif type(key) == "table" or box.tuple.is(key) then + elseif type(key) == "table" or is_tuple(key) then return key end return {key} @@ -618,7 +624,7 @@ local iterator_gen = function(param, state) if builtin.box_iterator_next(state, ptuple) ~= 0 then return box.error() -- error elseif ptuple[0] ~= nil then - return state, box.tuple.bless(ptuple[0]) -- new state, value + return state, tuple_bless(ptuple[0]) -- new state, value else return nil end @@ -696,12 +702,12 @@ function box.schema.space.bless(space) index_mt.__index = index_mt -- min and max index_mt.min_ffi = function(index, key) - local pkey, pkey_end = box.tuple.encode(key) + local pkey, pkey_end = tuple_encode(key) if builtin.box_index_min(index.space_id, index.id, pkey, pkey_end, ptuple) ~= 0 then box.error() -- error elseif ptuple[0] ~= nil then - return box.tuple.bless(ptuple[0]) + return tuple_bless(ptuple[0]) else return end @@ -711,12 +717,12 @@ function box.schema.space.bless(space) return internal.min(index.space_id, index.id, key); end index_mt.max_ffi = function(index, key) - local pkey, pkey_end = box.tuple.encode(key) + local pkey, pkey_end = tuple_encode(key) if builtin.box_index_max(index.space_id, index.id, pkey, pkey_end, ptuple) ~= 0 then box.error() -- error elseif ptuple[0] ~= nil then - return box.tuple.bless(ptuple[0]) + return tuple_bless(ptuple[0]) else return end @@ -731,7 +737,7 @@ function box.schema.space.bless(space) ptuple) ~= 0 then box.error() -- error elseif ptuple[0] ~= nil then - return box.tuple.bless(ptuple[0]) + return tuple_bless(ptuple[0]) else return end @@ -742,7 +748,7 @@ function box.schema.space.bless(space) end -- iteration index_mt.pairs_ffi = function(index, key, opts) - local pkey, pkey_end = box.tuple.encode(key) + local pkey, pkey_end = tuple_encode(key) local itype = check_iterator_type(opts, pkey + 1 >= pkey_end); local keybuf = ffi.string(pkey, pkey_end - pkey) @@ -767,7 +773,7 @@ function box.schema.space.bless(space) -- index subtree size index_mt.count_ffi = function(index, key, opts) - local pkey, pkey_end = box.tuple.encode(key) + local pkey, pkey_end = tuple_encode(key) local itype = check_iterator_type(opts, pkey + 1 >= pkey_end); local count = builtin.box_index_count(index.space_id, index.id, itype, pkey, pkey_end); @@ -789,12 +795,12 @@ function box.schema.space.bless(space) end index_mt.get_ffi = function(index, key) - local key, key_end = box.tuple.encode(key) + local key, key_end = tuple_encode(key) if builtin.box_index_get(index.space_id, index.id, key, key_end, ptuple) ~= 0 then return box.error() -- error elseif ptuple[0] ~= nil then - return box.tuple.bless(ptuple[0]) + return tuple_bless(ptuple[0]) else return end @@ -820,7 +826,7 @@ function box.schema.space.bless(space) end index_mt.select_ffi = function(index, key, opts) - local key, key_end = box.tuple.encode(key) + local key, key_end = tuple_encode(key) local iterator, offset, limit = check_select_opts(opts, key + 1 >= key_end) builtin.port_buf_create(port_buf) if builtin.box_select(port_buf, index.space_id, @@ -832,7 +838,7 @@ function box.schema.space.bless(space) local ret = {} local entry = port_buf.first for i=1,tonumber(port_buf.size),1 do - ret[i] = box.tuple.bless(entry.tuple) + ret[i] = tuple_bless(entry.tuple) entry = entry.next end builtin.port_buf_destroy(port_buf);