Mercurial > vim
changeset 29818:8ebfea14d9bb v9.0.0248
patch 9.0.0248: duplicate code in finding a script in the execution stack
Commit: https://github.com/vim/vim/commit/a247142ae45308087b25f91c8af48399c8ac2943
Author: zeertzjq <zeertzjq@outlook.com>
Date: Tue Aug 23 19:26:05 2022 +0100
patch 9.0.0248: duplicate code in finding a script in the execution stack
Problem: Duplicate code in finding a script in the execution stack.
Solution: Reduce duplicate code. (closes https://github.com/vim/vim/issues/10961)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 23 Aug 2022 20:30:03 +0200 |
parents | 1fa9e8491729 |
children | 38f88030a734 |
files | src/scriptfile.c src/version.c |
diffstat | 2 files changed, 9 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/scriptfile.c +++ b/src/scriptfile.c @@ -162,32 +162,21 @@ estack_sfile(estack_arg_T which UNUSED) // instead. if (which == ESTACK_SCRIPT) { - entry = ((estack_T *)exestack.ga_data) + exestack.ga_len - 1; // Walk the stack backwards, starting from the current frame. for (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) { - sctx_T *def_ctx = &entry->es_info.ufunc->uf_script_ctx; + sctx_T *def_ctx = entry->es_type == ETYPE_UFUNC + ? &entry->es_info.ufunc->uf_script_ctx + : acp_script_ctx(entry->es_info.aucmd); - if (def_ctx->sc_sid > 0) - return vim_strsave(SCRIPT_ITEM(def_ctx->sc_sid)->sn_name); - else - return NULL; - } - else if (entry->es_type == ETYPE_AUCMD) - { - sctx_T *def_ctx = acp_script_ctx(entry->es_info.aucmd); - - if (def_ctx->sc_sid > 0) - return vim_strsave(SCRIPT_ITEM(def_ctx->sc_sid)->sn_name); - else - return NULL; + return def_ctx->sc_sid > 0 + ? vim_strsave(SCRIPT_ITEM(def_ctx->sc_sid)->sn_name) + : NULL; } else if (entry->es_type == ETYPE_SCRIPT) - { return vim_strsave(entry->es_name); - } } return NULL; }