patch 9.0.1246: code is indented more than necessary
Problem: Code is indented more than necessary.
Solution: Use an early return where it makes sense. (Yegappan Lakshmanan,
closes #11887)
diff --git a/src/vim9script.c b/src/vim9script.c
index 0af7bb6..fd4658c 100644
--- a/src/vim9script.c
+++ b/src/vim9script.c
@@ -1007,42 +1007,43 @@
// The typval is moved into the sallvar_T.
script_hi = hash_find(script_ht, sv->sv_name);
all_hi = hash_find(all_ht, sv->sv_name);
- if (!HASHITEM_EMPTY(script_hi) && !HASHITEM_EMPTY(all_hi))
- {
- dictitem_T *di = HI2DI(script_hi);
- sallvar_T *sav = HI2SAV(all_hi);
- sallvar_T *sav_prev = NULL;
- // There can be multiple entries with the same name in different
- // blocks, find the right one.
- while (sav != NULL && sav->sav_var_vals_idx != idx)
- {
- sav_prev = sav;
- sav = sav->sav_next;
- }
- if (sav != NULL)
- {
- if (func_defined)
- {
- // move the typval from the dictitem to the sallvar
- sav->sav_tv = di->di_tv;
- di->di_tv.v_type = VAR_UNKNOWN;
- sav->sav_flags = di->di_flags;
- sav->sav_di = NULL;
- sv->sv_tv = &sav->sav_tv;
- }
- else
- {
- if (sav_prev == NULL)
- hash_remove(all_ht, all_hi, "hide variable");
- else
- sav_prev->sav_next = sav->sav_next;
- sv->sv_name = NULL;
- vim_free(sav);
- }
- delete_var(script_ht, script_hi);
- }
+ if (HASHITEM_EMPTY(script_hi) || HASHITEM_EMPTY(all_hi))
+ return;
+
+ dictitem_T *di = HI2DI(script_hi);
+ sallvar_T *sav = HI2SAV(all_hi);
+ sallvar_T *sav_prev = NULL;
+
+ // There can be multiple entries with the same name in different
+ // blocks, find the right one.
+ while (sav != NULL && sav->sav_var_vals_idx != idx)
+ {
+ sav_prev = sav;
+ sav = sav->sav_next;
}
+ if (sav == NULL)
+ return;
+
+ if (func_defined)
+ {
+ // move the typval from the dictitem to the sallvar
+ sav->sav_tv = di->di_tv;
+ di->di_tv.v_type = VAR_UNKNOWN;
+ sav->sav_flags = di->di_flags;
+ sav->sav_di = NULL;
+ sv->sv_tv = &sav->sav_tv;
+ }
+ else
+ {
+ if (sav_prev == NULL)
+ hash_remove(all_ht, all_hi, "hide variable");
+ else
+ sav_prev->sav_next = sav->sav_next;
+ sv->sv_name = NULL;
+ vim_free(sav);
+ }
+ delete_var(script_ht, script_hi);
}
/*