aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/generators/gen_api_dispatch.lua
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2024-02-08 13:40:35 +0100
committerbfredl <bjorn.linse@gmail.com>2024-02-08 14:40:34 +0100
commitaf5beac1bd7a68ff0a4e1a944853bacd6a6c0745 (patch)
treefef0a6f2a29a8fa760f767fb2782bf32d24084b1 /src/nvim/generators/gen_api_dispatch.lua
parent1f9da3d0835af2cfe937de250c2cde3a59e1677e (diff)
downloadrneovim-af5beac1bd7a68ff0a4e1a944853bacd6a6c0745.tar.gz
rneovim-af5beac1bd7a68ff0a4e1a944853bacd6a6c0745.tar.bz2
rneovim-af5beac1bd7a68ff0a4e1a944853bacd6a6c0745.zip
refactor(api): refactor more api functions to use arena return
Currently having two separate memory strategies for API return values is a bit unnecessary, and mostly a consequence of converting the hot spot cases which needed it first. But there is really no downside to using arena everywhere (which implies also directly using strings which are allocated earlier or even statically, without copy). There only restriction is we need to know the size of arrays in advance, but this info can often be passed on from some earlier stage if it is missing. This collects some "small" cases. The more complex stuff will get a PR each.
Diffstat (limited to 'src/nvim/generators/gen_api_dispatch.lua')
-rw-r--r--src/nvim/generators/gen_api_dispatch.lua57
1 files changed, 19 insertions, 38 deletions
diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua
index 14b4ecb1a3..da3010878d 100644
--- a/src/nvim/generators/gen_api_dispatch.lua
+++ b/src/nvim/generators/gen_api_dispatch.lua
@@ -535,7 +535,6 @@ for i = 1, #functions do
end
-- function call
- local call_args = table.concat(args, ', ')
output:write('\n ')
if fn.return_type ~= 'void' then
-- has a return value, prefix the call with a declaration
@@ -545,58 +544,40 @@ for i = 1, #functions do
-- write the function name and the opening parenthesis
output:write(fn.name .. '(')
+ local call_args = {}
if fn.receives_channel_id then
- -- if the function receives the channel id, pass it as first argument
- if #args > 0 or fn.can_fail then
- output:write('channel_id, ')
- if fn.receives_array_args then
- -- if the function receives the array args, pass it the second argument
- output:write('args, ')
- end
- output:write(call_args)
- else
- output:write('channel_id')
- if fn.receives_array_args then
- output:write(', args')
- end
- end
- else
- if fn.receives_array_args then
- if #args > 0 or fn.call_fail then
- output:write('args, ' .. call_args)
- else
- output:write('args')
- end
- else
- output:write(call_args)
- end
+ table.insert(call_args, 'channel_id')
+ end
+
+ if fn.receives_array_args then
+ table.insert(call_args, 'args')
+ end
+
+ for _, a in ipairs(args) do
+ table.insert(call_args, a)
end
if fn.arena_return then
- output:write(', arena')
+ table.insert(call_args, 'arena')
end
if fn.has_lua_imp then
- if #args > 0 then
- output:write(', NULL')
- else
- output:write('NULL')
- end
+ table.insert(call_args, 'NULL')
end
if fn.can_fail then
+ table.insert(call_args, 'error')
+ end
+
+ output:write(table.concat(call_args, ', '))
+ output:write(');\n')
+
+ if fn.can_fail then
-- if the function can fail, also pass a pointer to the local error object
- if #args > 0 then
- output:write(', error);\n')
- else
- output:write('error);\n')
- end
-- and check for the error
output:write('\n if (ERROR_SET(error)) {')
output:write('\n goto cleanup;')
output:write('\n }\n')
- else
- output:write(');\n')
end
local ret_type = real_type(fn.return_type)