aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/generators
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2024-07-02 13:45:50 +0200
committerbfredl <bjorn.linse@gmail.com>2024-08-05 11:12:44 +0200
commitf926cc32c9262b6254e2843276b951cef9da1afe (patch)
tree56f13240abae6ec0f3b13022b011da84948788c0 /src/nvim/generators
parent0c2860d9e5ec5417a94db6e3edd237578b76d418 (diff)
downloadrneovim-f926cc32c9262b6254e2843276b951cef9da1afe.tar.gz
rneovim-f926cc32c9262b6254e2843276b951cef9da1afe.tar.bz2
rneovim-f926cc32c9262b6254e2843276b951cef9da1afe.zip
refactor(shada): rework msgpack decoding without msgpack-c
This also makes shada reading slightly faster due to avoiding some copying and allocation. Use keysets to drive decoding of msgpack maps for shada entries.
Diffstat (limited to 'src/nvim/generators')
-rw-r--r--src/nvim/generators/c_grammar.lua6
-rw-r--r--src/nvim/generators/gen_api_dispatch.lua27
-rw-r--r--src/nvim/generators/hashy.lua22
3 files changed, 31 insertions, 24 deletions
diff --git a/src/nvim/generators/c_grammar.lua b/src/nvim/generators/c_grammar.lua
index 9ce9f3d7a6..4e7de7adb4 100644
--- a/src/nvim/generators/c_grammar.lua
+++ b/src/nvim/generators/c_grammar.lua
@@ -91,7 +91,9 @@ local c_proto = Ct(
* (P(';') + (P('{') * nl + (impl_line ^ 0) * P('}')))
)
-local c_field = Ct(Cg(c_id, 'type') * ws * Cg(c_id, 'name') * fill * P(';') * fill)
+local dict_key = P('DictKey(') * Cg(rep1(any - P(')')), 'dict_key') * P(')')
+local keyset_field =
+ Ct(Cg(c_id, 'type') * ws * Cg(c_id, 'name') * fill * (dict_key ^ -1) * fill * P(';') * fill)
local c_keyset = Ct(
P('typedef')
* ws
@@ -99,7 +101,7 @@ local c_keyset = Ct(
* fill
* P('{')
* fill
- * Cg(Ct(c_field ^ 1), 'fields')
+ * Cg(Ct(keyset_field ^ 1), 'fields')
* P('}')
* fill
* P('Dict')
diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua
index 61c80a3d2e..3567831c41 100644
--- a/src/nvim/generators/gen_api_dispatch.lua
+++ b/src/nvim/generators/gen_api_dispatch.lua
@@ -72,14 +72,19 @@ local keysets = {}
local function add_keyset(val)
local keys = {}
local types = {}
+ local c_names = {}
local is_set_name = 'is_set__' .. val.keyset_name .. '_'
local has_optional = false
for i, field in ipairs(val.fields) do
+ local dict_key = field.dict_key or field.name
if field.type ~= 'Object' then
- types[field.name] = field.type
+ types[dict_key] = field.type
end
if field.name ~= is_set_name and field.type ~= 'OptionalKeys' then
- table.insert(keys, field.name)
+ table.insert(keys, dict_key)
+ if dict_key ~= field.name then
+ c_names[dict_key] = field.name
+ end
else
if i > 1 then
error("'is_set__{type}_' must be first if present")
@@ -94,6 +99,7 @@ local function add_keyset(val)
table.insert(keysets, {
name = val.keyset_name,
keys = keys,
+ c_names = c_names,
types = types,
has_optional = has_optional,
})
@@ -332,19 +338,6 @@ output:write([[
keysets_defs:write('// IWYU pragma: private, include "nvim/api/private/dispatch.h"\n\n')
for _, k in ipairs(keysets) do
- local c_name = {}
-
- for i = 1, #k.keys do
- -- some keys, like "register" are c keywords and get
- -- escaped with a trailing _ in the struct.
- if vim.endswith(k.keys[i], '_') then
- local orig = k.keys[i]
- k.keys[i] = string.sub(k.keys[i], 1, #k.keys[i] - 1)
- c_name[k.keys[i]] = orig
- k.types[k.keys[i]] = k.types[orig]
- end
- end
-
local neworder, hashfun = hashy.hashy_hash(k.name, k.keys, function(idx)
return k.name .. '_table[' .. idx .. '].str'
end)
@@ -354,6 +347,8 @@ for _, k in ipairs(keysets) do
local function typename(type)
if type == 'HLGroupID' then
return 'kObjectTypeInteger'
+ elseif type == 'StringArray' then
+ return 'kUnpackTypeStringArray'
elseif type ~= nil then
return 'kObjectType' .. type
else
@@ -374,7 +369,7 @@ for _, k in ipairs(keysets) do
.. '", offsetof(KeyDict_'
.. k.name
.. ', '
- .. (c_name[key] or key)
+ .. (k.c_names[key] or key)
.. '), '
.. typename(k.types[key])
.. ', '
diff --git a/src/nvim/generators/hashy.lua b/src/nvim/generators/hashy.lua
index 711e695742..ea35064962 100644
--- a/src/nvim/generators/hashy.lua
+++ b/src/nvim/generators/hashy.lua
@@ -73,11 +73,15 @@ function M.switcher(put, tab, maxlen, worst_buck_size)
vim.list_extend(neworder, buck)
local endidx = #neworder
put(" case '" .. c .. "': ")
- put('low = ' .. startidx .. '; ')
- if bucky then
- put('high = ' .. endidx .. '; ')
+ if len == 1 then
+ put('return ' .. startidx .. ';\n')
+ else
+ put('low = ' .. startidx .. '; ')
+ if bucky then
+ put('high = ' .. endidx .. '; ')
+ end
+ put 'break;\n'
end
- put 'break;\n'
end
put ' default: break;\n'
put ' }\n '
@@ -105,13 +109,19 @@ function M.hashy_hash(name, strings, access)
end
local len_pos_buckets, maxlen, worst_buck_size = M.build_pos_hash(strings)
put('int ' .. name .. '_hash(const char *str, size_t len)\n{\n')
- if worst_buck_size > 1 then
+ if maxlen == 1 then
+ put('\n') -- nothing
+ elseif worst_buck_size > 1 then
put(' int low = 0, high = 0;\n')
else
put(' int low = -1;\n')
end
local neworder = M.switcher(put, len_pos_buckets, maxlen, worst_buck_size)
- if worst_buck_size > 1 then
+ if maxlen == 1 then
+ put([[
+ return -1;
+]])
+ elseif worst_buck_size > 1 then
put([[
for (int i = low; i < high; i++) {
if (!memcmp(str, ]] .. access('i') .. [[, len)) {