aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-04-25 08:26:49 +0800
committerGitHub <noreply@github.com>2024-04-25 08:26:49 +0800
commitc32fcd1ed527236e52cfd78033685e713ec36d75 (patch)
tree1749830896b6c1cd31dbe8ea762a5d650f287247 /src
parent7f084770c23855083776b0598f2f54bb59a06875 (diff)
downloadrneovim-c32fcd1ed527236e52cfd78033685e713ec36d75.tar.gz
rneovim-c32fcd1ed527236e52cfd78033685e713ec36d75.tar.bz2
rneovim-c32fcd1ed527236e52cfd78033685e713ec36d75.zip
refactor(source): remove unnecessary concatenation with Lua (#28499)
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval.c4
-rw-r--r--src/nvim/lua/executor.c13
-rw-r--r--src/nvim/runtime.c15
3 files changed, 8 insertions, 24 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 213948a028..70cf2b973d 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -7904,8 +7904,8 @@ hashtab_T *find_var_ht_dict(const char *name, const size_t name_len, const char
.channel_id = LUA_INTERNAL_CALL,
};
bool should_free;
- // should_free is ignored as script_sctx will be resolved to a fnmae
- // & new_script_item will consume it.
+ // should_free is ignored as script_ctx will be resolved to a fname
+ // and new_script_item() will consume it.
char *sc_name = get_scriptname(last_set, &should_free);
new_script_item(sc_name, &current_sctx.sc_sid);
}
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index 9096cac619..a76b8213e5 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -1487,7 +1487,7 @@ static void nlua_typval_exec(const char *lcmd, size_t lcmd_len, const char *name
}
}
-int nlua_source_using_linegetter(LineGetter fgetline, void *cookie, char *name)
+void nlua_source_str(const char *code, char *name)
{
const sctx_T save_current_sctx = current_sctx;
current_sctx.sc_sid = SID_STR;
@@ -1495,22 +1495,11 @@ int nlua_source_using_linegetter(LineGetter fgetline, void *cookie, char *name)
current_sctx.sc_lnum = 0;
estack_push(ETYPE_SCRIPT, name, 0);
- garray_T ga;
- char *line = NULL;
-
- ga_init(&ga, (int)sizeof(char *), 10);
- while ((line = fgetline(0, cookie, 0, false)) != NULL) {
- GA_APPEND(char *, &ga, line);
- }
- char *code = ga_concat_strings_sep(&ga, "\n");
size_t len = strlen(code);
nlua_typval_exec(code, len, name, NULL, 0, false, NULL);
estack_pop();
current_sctx = save_current_sctx;
- ga_clear_strings(&ga);
- xfree(code);
- return OK;
}
/// Call a LuaCallable given some typvals
diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c
index 9b8bfd4495..d913d311db 100644
--- a/src/nvim/runtime.c
+++ b/src/nvim/runtime.c
@@ -1889,11 +1889,6 @@ static bool concat_continued_line(garray_T *const ga, const int init_growsize, c
}
typedef struct {
- linenr_T curr_lnum;
- const linenr_T final_lnum;
-} GetBufferLineCookie;
-
-typedef struct {
char *buf;
size_t offset;
} GetStrLineCookie;
@@ -2009,15 +2004,15 @@ void cmd_source_buffer(const exarg_T *const eap, bool ex_lua)
ga_append(&ga, NL);
}
((char *)ga.ga_data)[ga.ga_len - 1] = NUL;
- const GetStrLineCookie cookie = {
- .buf = ga.ga_data,
- .offset = 0,
- };
if (ex_lua || strequal(curbuf->b_p_ft, "lua")
|| (curbuf->b_fname && path_with_extension(curbuf->b_fname, "lua"))) {
char *name = ex_lua ? ":{range}lua" : ":source (no file)";
- nlua_source_using_linegetter(get_str_line, (void *)&cookie, name);
+ nlua_source_str(ga.ga_data, name);
} else {
+ const GetStrLineCookie cookie = {
+ .buf = ga.ga_data,
+ .offset = 0,
+ };
source_using_linegetter((void *)&cookie, get_str_line, ":source (no file)");
}
ga_clear(&ga);