@@ -163,18 +163,7 @@ static dict_T vimvardict; // Dictionary with v: variables
163163// for VIM_VERSION_ defines
164164#include "version.h"
165165
166- /*
167- * Array to hold the hashtab with variables local to each sourced script.
168- * Each item holds a variable (nameless) that points to the dict_T.
169- */
170- typedef struct
171- {
172- dictitem_T sv_var ;
173- dict_T sv_dict ;
174- } scriptvar_T ;
175-
176- static garray_T ga_scripts = {0 , 0 , sizeof (scriptvar_T * ), 4 , NULL };
177- #define SCRIPT_SV (id ) (((scriptvar_T **)ga_scripts.ga_data)[(id) - 1])
166+ #define SCRIPT_SV (id ) (SCRIPT_ITEM(id).sn_vars)
178167#define SCRIPT_VARS (id ) (SCRIPT_SV(id)->sv_dict.dv_hashtab)
179168
180169static void ex_let_const (exarg_T * eap , int is_const );
@@ -289,14 +278,12 @@ evalvars_clear(void)
289278 // global variables
290279 vars_clear (& globvarht );
291280
292- // Script-local variables. First clear all the variables and in a second
293- // loop free the scriptvar_T, because a variable in one script might hold
294- // a reference to the whole scope of another script.
295- for (i = 1 ; i <= ga_scripts .ga_len ; ++ i )
281+ // Script-local variables. Clear all the variables here.
282+ // The scriptvar_T is cleared later in free_scriptnames(), because a
283+ // variable in one script might hold a reference to the whole scope of
284+ // another script.
285+ for (i = 1 ; i <= script_items .ga_len ; ++ i )
296286 vars_clear (& SCRIPT_VARS (i ));
297- for (i = 1 ; i <= ga_scripts .ga_len ; ++ i )
298- vim_free (SCRIPT_SV (i ));
299- ga_clear (& ga_scripts );
300287}
301288#endif
302289
@@ -318,7 +305,7 @@ garbage_collect_scriptvars(int copyID)
318305 int i ;
319306 int abort = FALSE;
320307
321- for (i = 1 ; i <= ga_scripts .ga_len ; ++ i )
308+ for (i = 1 ; i <= script_items .ga_len ; ++ i )
322309 abort = abort || set_ref_in_ht (& SCRIPT_VARS (i ), copyID , NULL );
323310
324311 return abort ;
@@ -538,7 +525,7 @@ list_vim_vars(int *first)
538525 static void
539526list_script_vars (int * first )
540527{
541- if (current_sctx .sc_sid > 0 && current_sctx .sc_sid <= ga_scripts .ga_len )
528+ if (current_sctx .sc_sid > 0 && current_sctx .sc_sid <= script_items .ga_len )
542529 list_hashtable_vars (& SCRIPT_VARS (current_sctx .sc_sid ),
543530 "s:" , FALSE, first );
544531}
@@ -2433,7 +2420,7 @@ find_var_ht(char_u *name, char_u **varname)
24332420 return get_funccal_local_ht ();
24342421 if (* name == 's' // script variable
24352422 && current_sctx .sc_sid > 0
2436- && current_sctx .sc_sid <= ga_scripts .ga_len )
2423+ && current_sctx .sc_sid <= script_items .ga_len )
24372424 return & SCRIPT_VARS (current_sctx .sc_sid );
24382425 return NULL ;
24392426}
@@ -2461,32 +2448,13 @@ get_var_value(char_u *name)
24612448 void
24622449new_script_vars (scid_T id )
24632450{
2464- int i ;
2465- hashtab_T * ht ;
24662451 scriptvar_T * sv ;
24672452
2468- if (ga_grow (& ga_scripts , (int )(id - ga_scripts .ga_len )) == OK )
2469- {
2470- // Re-allocating ga_data means that an ht_array pointing to
2471- // ht_smallarray becomes invalid. We can recognize this: ht_mask is
2472- // at its init value. Also reset "v_dict", it's always the same.
2473- for (i = 1 ; i <= ga_scripts .ga_len ; ++ i )
2474- {
2475- ht = & SCRIPT_VARS (i );
2476- if (ht -> ht_mask == HT_INIT_SIZE - 1 )
2477- ht -> ht_array = ht -> ht_smallarray ;
2478- sv = SCRIPT_SV (i );
2479- sv -> sv_var .di_tv .vval .v_dict = & sv -> sv_dict ;
2480- }
2481-
2482- while (ga_scripts .ga_len < id )
2483- {
2484- sv = SCRIPT_SV (ga_scripts .ga_len + 1 ) =
2485- ALLOC_CLEAR_ONE (scriptvar_T );
2486- init_var_dict (& sv -> sv_dict , & sv -> sv_var , VAR_SCOPE );
2487- ++ ga_scripts .ga_len ;
2488- }
2489- }
2453+ sv = ALLOC_CLEAR_ONE (scriptvar_T );
2454+ if (sv == NULL )
2455+ return ;
2456+ init_var_dict (& sv -> sv_dict , & sv -> sv_var , VAR_SCOPE );
2457+ SCRIPT_ITEM (id ).sn_vars = sv ;
24902458}
24912459
24922460/*
0 commit comments