Skip to content

Commit 6c01283

Browse files
h-eastchrisbra
authored andcommitted
patch 9.1.1148: Vim9: finding imported scripts can be further improved
Problem: Vim9: finding imported scripts can be further improved (after v9.1.1146) Solution: Eliminate extra find_imported() call (Hirohito Higashi) related: #16602 related: #16660 closes: #16731 Signed-off-by: Hirohito Higashi <h.east.727@gmail.com> Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 00a00f5 commit 6c01283

4 files changed

Lines changed: 28 additions & 17 deletions

File tree

src/proto/vim9expr.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
int generate_ppconst(cctx_T *cctx, ppconst_T *ppconst);
33
void clear_ppconst(ppconst_T *ppconst);
44
int compile_member(int is_slice, int *keeping_dict, cctx_T *cctx);
5-
int compile_load_scriptvar(cctx_T *cctx, char_u *name, char_u *start, char_u **end);
5+
int compile_load_scriptvar(cctx_T *cctx, char_u *name, char_u *start, char_u **end, imported_T *import);
66
int compile_load(char_u **arg, char_u *end_arg, cctx_T *cctx, int is_expr, int error);
77
int compile_arguments(char_u **arg, cctx_T *cctx, int *argcount, ca_special_T special_fn);
88
char_u *to_name_end(char_u *arg, int use_namespace);

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
1148,
707709
/**/
708710
1147,
709711
/**/

src/vim9compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,7 @@ generate_loadvar(cctx_T *cctx, lhs_T *lhs)
13741374
case dest_script:
13751375
case dest_script_v9:
13761376
res = compile_load_scriptvar(cctx,
1377-
name + (name[1] == ':' ? 2 : 0), NULL, NULL);
1377+
name + (name[1] == ':' ? 2 : 0), NULL, NULL, NULL);
13781378
break;
13791379
case dest_env:
13801380
// Include $ in the name here

src/vim9expr.c

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -538,11 +538,12 @@ compile_load_scriptvar(
538538
cctx_T *cctx,
539539
char_u *name, // variable NUL terminated
540540
char_u *start, // start of variable
541-
char_u **end) // end of variable, may be NULL
541+
char_u **end, // end of variable, may be NULL
542+
imported_T *import) // found imported item, can be NULL
542543
{
543544
scriptitem_T *si;
544545
int idx;
545-
imported_T *import;
546+
imported_T *imp;
546547

547548
if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
548549
return FAIL;
@@ -557,8 +558,14 @@ compile_load_scriptvar(
557558
return OK;
558559
}
559560

560-
import = end == NULL ? NULL : find_imported(name, 0, FALSE);
561-
if (import != NULL)
561+
if (end == NULL)
562+
imp = NULL;
563+
else if (import == NULL)
564+
imp = find_imported(name, 0, FALSE);
565+
else
566+
imp = import;
567+
568+
if (imp != NULL)
562569
{
563570
char_u *p = skipwhite(*end);
564571
char_u *exp_name;
@@ -568,8 +575,8 @@ compile_load_scriptvar(
568575
int done = FALSE;
569576
int res = OK;
570577

571-
check_script_symlink(import->imp_sid);
572-
import_check_sourced_sid(&import->imp_sid);
578+
check_script_symlink(imp->imp_sid);
579+
import_check_sourced_sid(&imp->imp_sid);
573580

574581
// Need to lookup the member.
575582
if (*p != '.')
@@ -591,11 +598,11 @@ compile_load_scriptvar(
591598
cc = *p;
592599
*p = NUL;
593600

594-
si = SCRIPT_ITEM(import->imp_sid);
601+
si = SCRIPT_ITEM(imp->imp_sid);
595602
if (si->sn_import_autoload && si->sn_state == SN_STATE_NOT_LOADED)
596603
// "import autoload './dir/script.vim'" or
597604
// "import autoload './autoload/script.vim'" - load script first
598-
res = generate_SOURCE(cctx, import->imp_sid);
605+
res = generate_SOURCE(cctx, imp->imp_sid);
599606

600607
if (res == OK)
601608
{
@@ -624,17 +631,17 @@ compile_load_scriptvar(
624631
{
625632
char_u sid_name[MAX_FUNC_NAME_LEN];
626633

627-
func_name_with_sid(exp_name, import->imp_sid, sid_name);
634+
func_name_with_sid(exp_name, imp->imp_sid, sid_name);
628635
res = generate_PUSHFUNC(cctx, sid_name, &t_func_any, TRUE);
629636
}
630637
else
631638
res = generate_OLDSCRIPT(cctx, ISN_LOADEXPORT, exp_name,
632-
import->imp_sid, &t_any);
639+
imp->imp_sid, &t_any);
633640
done = TRUE;
634641
}
635642
else
636643
{
637-
idx = find_exported(import->imp_sid, exp_name, &ufunc, &type,
644+
idx = find_exported(imp->imp_sid, exp_name, &ufunc, &type,
638645
cctx, NULL, TRUE);
639646
}
640647
}
@@ -656,7 +663,7 @@ compile_load_scriptvar(
656663
}
657664

658665
generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT,
659-
import->imp_sid,
666+
imp->imp_sid,
660667
idx,
661668
type);
662669
return OK;
@@ -771,7 +778,7 @@ compile_load(
771778
res = generate_funcref(cctx, name, FALSE);
772779
else
773780
res = compile_load_scriptvar(cctx, name,
774-
NULL, &end);
781+
NULL, &end, NULL);
775782
break;
776783
case 'g': if (vim_strchr(name, AUTOLOAD_CHAR) == NULL)
777784
{
@@ -887,11 +894,13 @@ compile_load(
887894
}
888895
else
889896
{
897+
imported_T *imp = NULL;
898+
890899
// "var" can be script-local even without using "s:" if it
891900
// already exists in a Vim9 script or when it's imported.
892901
if (script_var_exists(*arg, len, cctx, NULL) == OK
893-
|| find_imported(name, 0, FALSE) != NULL)
894-
res = compile_load_scriptvar(cctx, name, *arg, &end);
902+
|| (imp = find_imported(name, 0, FALSE)) != NULL)
903+
res = compile_load_scriptvar(cctx, name, *arg, &end, imp);
895904

896905
// When evaluating an expression and the name starts with an
897906
// uppercase letter it can be a user defined function.

0 commit comments

Comments
 (0)