mirror of
https://github.com/neovim/neovim.git
synced 2024-12-25 05:35:10 -07:00
refactor(source): remove unnecessary concatenation with Lua (#28499)
This commit is contained in:
parent
7f084770c2
commit
c32fcd1ed5
@ -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, ¤t_sctx.sc_sid);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -1888,11 +1888,6 @@ static bool concat_continued_line(garray_T *const ga, const int init_growsize, c
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
linenr_T curr_lnum;
|
||||
const linenr_T final_lnum;
|
||||
} GetBufferLineCookie;
|
||||
|
||||
typedef struct {
|
||||
char *buf;
|
||||
size_t offset;
|
||||
@ -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;
|
||||
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_str(ga.ga_data, name);
|
||||
} else {
|
||||
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);
|
||||
} else {
|
||||
source_using_linegetter((void *)&cookie, get_str_line, ":source (no file)");
|
||||
}
|
||||
ga_clear(&ga);
|
||||
|
Loading…
Reference in New Issue
Block a user