]> granicus.if.org Git - vim/commitdiff
patch 9.0.0248: duplicate code in finding a script in the execution stack v9.0.0248
authorzeertzjq <zeertzjq@outlook.com>
Tue, 23 Aug 2022 18:26:05 +0000 (19:26 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 23 Aug 2022 18:26:05 +0000 (19:26 +0100)
Problem:    Duplicate code in finding a script in the execution stack.
Solution:   Reduce duplicate code. (closes #10961)

src/scriptfile.c
src/version.c

index aae3be20abd57f46402a6ae5547a175ad38c3d1e..c176763d5118c16f4777635d5ae17d9b495dd2fd 100644 (file)
@@ -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;
     }
index 66ef53ca9f71e4b3ea14210f995634ca5ae930aa..0a3d26b1ebe77c3bbfb0a6bb23933eafeefe0bfe 100644 (file)
@@ -731,6 +731,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    248,
 /**/
     247,
 /**/