diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-06-18 12:02:31 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-18 12:02:31 +0800 |
commit | b0c336eaf8e7dd0e52e08195f46fd309fc138ea1 (patch) | |
tree | 66aafb47719eb5e4b54ae4a9b3ffeb57222b6d4a | |
parent | 1a1c766049826b6049610edda8f72eac1f75b38d (diff) | |
download | rneovim-b0c336eaf8e7dd0e52e08195f46fd309fc138ea1.tar.gz rneovim-b0c336eaf8e7dd0e52e08195f46fd309fc138ea1.tar.bz2 rneovim-b0c336eaf8e7dd0e52e08195f46fd309fc138ea1.zip |
refactor(lua): remove unnecessary strlen() in nlua_expand_pat() (#29388)
Also change the initial value of `status` to `FAIL`, as that'll avoid
unnecessary assignments.
-rw-r--r-- | src/nvim/lua/executor.c | 16 | ||||
-rw-r--r-- | test/functional/editor/completion_spec.lua | 12 |
2 files changed, 8 insertions, 20 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index af218443b9..bac6f4ca9a 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1931,7 +1931,7 @@ static garray_T expand_result_array = GA_EMPTY_INIT_VALUE; void nlua_expand_pat(expand_T *xp, const char *pat) { lua_State *const lstate = global_lstate; - int status = OK; + int status = FAIL; // [ vim ] lua_getglobal(lstate, "vim"); @@ -1940,12 +1940,11 @@ void nlua_expand_pat(expand_T *xp, const char *pat) lua_getfield(lstate, -1, "_expand_pat"); luaL_checktype(lstate, -1, LUA_TFUNCTION); - // [ vim, vim._expand_pat, buf ] - lua_pushlstring(lstate, pat, strlen(pat)); + // [ vim, vim._expand_pat, pat ] + lua_pushstring(lstate, pat); if (nlua_pcall(lstate, 1, 2) != 0) { - nlua_error(lstate, - _("Error executing vim._expand_pat: %.*s")); + nlua_error(lstate, _("Error executing vim._expand_pat: %.*s")); return; } @@ -1954,30 +1953,27 @@ void nlua_expand_pat(expand_T *xp, const char *pat) Arena arena = ARENA_EMPTY; int prefix_len = (int)nlua_pop_Integer(lstate, &arena, &err); if (ERROR_SET(&err)) { - status = FAIL; goto cleanup; } Array completions = nlua_pop_Array(lstate, &arena, &err); if (ERROR_SET(&err)) { - status = FAIL; goto cleanup_array; } ga_clear(&expand_result_array); ga_init(&expand_result_array, (int)sizeof(char *), 80); + for (size_t i = 0; i < completions.size; i++) { Object v = completions.items[i]; - if (v.type != kObjectTypeString) { - status = FAIL; goto cleanup_array; } - GA_APPEND(char *, &expand_result_array, string_to_cstr(v.data.string)); } xp->xp_pattern += prefix_len; + status = OK; cleanup_array: arena_mem_free(arena_finish(&arena)); diff --git a/test/functional/editor/completion_spec.lua b/test/functional/editor/completion_spec.lua index b42310fa81..405af5fcfd 100644 --- a/test/functional/editor/completion_spec.lua +++ b/test/functional/editor/completion_spec.lua @@ -816,22 +816,14 @@ describe('completion', function() feed(':lua math.a<Tab>') screen:expect([[ | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 {100:abs}{3: acos asin atan atan2 }| :lua math.abs^ | ]]) feed('<Tab>') screen:expect([[ | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 {3:abs }{100:acos}{3: asin atan atan2 }| :lua math.acos^ | ]]) |