mirror of
https://github.com/neovim/neovim.git
synced 2025-09-08 20:38:18 +00:00
vim-patch:9.0.0248: duplicate code in finding a script in the execution stack (#19917)
Problem: Duplicate code in finding a script in the execution stack.
Solution: Reduce duplicate code. (closes vim/vim#10961)
a247142ae4
This commit is contained in:
@@ -116,25 +116,15 @@ char *estack_sfile(estack_arg_T which)
|
|||||||
// where it is defined, at script level the current script path is returned
|
// where it is defined, at script level the current script path is returned
|
||||||
// instead.
|
// instead.
|
||||||
if (which == ESTACK_SCRIPT) {
|
if (which == ESTACK_SCRIPT) {
|
||||||
assert(entry == ((estack_T *)exestack.ga_data) + exestack.ga_len - 1);
|
|
||||||
// Walk the stack backwards, starting from the current frame.
|
// Walk the stack backwards, starting from the current frame.
|
||||||
for (int idx = exestack.ga_len - 1; idx >= 0; idx--, entry--) {
|
for (int idx = exestack.ga_len - 1; idx >= 0; idx--, entry--) {
|
||||||
if (entry->es_type == ETYPE_UFUNC) {
|
if (entry->es_type == ETYPE_UFUNC || entry->es_type == ETYPE_AUCMD) {
|
||||||
const sctx_T *const def_ctx = &entry->es_info.ufunc->uf_script_ctx;
|
const sctx_T *const def_ctx = (entry->es_type == ETYPE_UFUNC
|
||||||
|
? &entry->es_info.ufunc->uf_script_ctx
|
||||||
if (def_ctx->sc_sid > 0) {
|
: &entry->es_info.aucmd->script_ctx);
|
||||||
return xstrdup((char *)(SCRIPT_ITEM(def_ctx->sc_sid).sn_name));
|
return def_ctx->sc_sid > 0
|
||||||
} else {
|
? xstrdup((char *)(SCRIPT_ITEM(def_ctx->sc_sid).sn_name))
|
||||||
return NULL;
|
: NULL;
|
||||||
}
|
|
||||||
} else if (entry->es_type == ETYPE_AUCMD) {
|
|
||||||
const sctx_T *const def_ctx = &entry->es_info.aucmd->script_ctx;
|
|
||||||
|
|
||||||
if (def_ctx->sc_sid > 0) {
|
|
||||||
return xstrdup((char *)(SCRIPT_ITEM(def_ctx->sc_sid).sn_name));
|
|
||||||
} else {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
} else if (entry->es_type == ETYPE_SCRIPT) {
|
} else if (entry->es_type == ETYPE_SCRIPT) {
|
||||||
return xstrdup(entry->es_name);
|
return xstrdup(entry->es_name);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user