patch 8.2.3275: optimizer can use hints about ga_grow() normally succeeding
Problem: Optimizer can use hints about ga_grow() normally succeeding.
Solution: Use GA_GROW_FAILS() and GA_GROW_OK() in several places. (Dominique
Pellé, issue #8635)
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 8e7be28..15e6e63 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -548,7 +548,7 @@
isn_T *isn;
RETURN_NULL_IF_SKIP(cctx);
- if (ga_grow(instr, 1) == FAIL)
+ if (GA_GROW_FAILS(instr, 1))
return NULL;
isn = ((isn_T *)instr->ga_data) + instr->ga_len;
isn->isn_type = isn_type;
@@ -585,7 +585,7 @@
if ((isn = generate_instr(cctx, isn_type)) == NULL)
return NULL;
- if (ga_grow(stack, 1) == FAIL)
+ if (GA_GROW_FAILS(stack, 1))
return NULL;
((type_T **)stack->ga_data)[stack->ga_len] = type == NULL ? &t_any : type;
++stack->ga_len;
@@ -1288,7 +1288,7 @@
isn->isn_arg.getitem.gi_with_op = with_op;
// add the item type to the type stack
- if (ga_grow(stack, 1) == FAIL)
+ if (GA_GROW_FAILS(stack, 1))
return FAIL;
((type_T **)stack->ga_data)[stack->ga_len] = item_type;
++stack->ga_len;
@@ -1590,7 +1590,7 @@
stack->ga_len -= count;
// add the list type to the type stack
- if (ga_grow(stack, 1) == FAIL)
+ if (GA_GROW_FAILS(stack, 1))
return FAIL;
((type_T **)stack->ga_data)[stack->ga_len] = type;
++stack->ga_len;
@@ -1626,7 +1626,7 @@
stack->ga_len -= 2 * count;
// add the dict type to the type stack
- if (ga_grow(stack, 1) == FAIL)
+ if (GA_GROW_FAILS(stack, 1))
return FAIL;
((type_T **)stack->ga_data)[stack->ga_len] = type;
++stack->ga_len;
@@ -1654,7 +1654,7 @@
if (ufunc->uf_flags & FC_CLOSURE)
cctx->ctx_ufunc->uf_flags |= FC_CLOSURE;
- if (ga_grow(stack, 1) == FAIL)
+ if (GA_GROW_FAILS(stack, 1))
return FAIL;
((type_T **)stack->ga_data)[stack->ga_len] =
ufunc->uf_func_type == NULL ? &t_func_any : ufunc->uf_func_type;
@@ -1759,7 +1759,7 @@
return FAIL;
isn->isn_arg.forloop.for_idx = loop_idx;
- if (ga_grow(stack, 1) == FAIL)
+ if (GA_GROW_FAILS(stack, 1))
return FAIL;
// type doesn't matter, will be stored next
((type_T **)stack->ga_data)[stack->ga_len] = &t_any;
@@ -1841,7 +1841,7 @@
// Drop the argument types and push the return type.
stack->ga_len -= argcount;
- if (ga_grow(stack, 1) == FAIL)
+ if (GA_GROW_FAILS(stack, 1))
return FAIL;
((type_T **)stack->ga_data)[stack->ga_len] =
internal_func_ret_type(func_idx, argcount, argtypes);
@@ -2031,7 +2031,7 @@
}
stack->ga_len -= argcount; // drop the arguments
- if (ga_grow(stack, 1) == FAIL)
+ if (GA_GROW_FAILS(stack, 1))
return FAIL;
// add return value
((type_T **)stack->ga_data)[stack->ga_len] = ufunc->uf_ret_type;
@@ -2056,7 +2056,7 @@
isn->isn_arg.ufunc.cuf_argcount = argcount;
stack->ga_len -= argcount; // drop the arguments
- if (ga_grow(stack, 1) == FAIL)
+ if (GA_GROW_FAILS(stack, 1))
return FAIL;
// add return value
((type_T **)stack->ga_data)[stack->ga_len] = &t_any;
@@ -2265,7 +2265,7 @@
return FAIL;
isn->isn_arg.string = vim_strsave(line);
- if (ga_grow(stack, 1) == FAIL)
+ if (GA_GROW_FAILS(stack, 1))
return FAIL;
((type_T **)stack->ga_data)[stack->ga_len] = &t_any;
++stack->ga_len;
@@ -2297,7 +2297,7 @@
return FAIL;
isn->isn_arg.string = range;
- if (ga_grow(stack, 1) == FAIL)
+ if (GA_GROW_FAILS(stack, 1))
return FAIL;
((type_T **)stack->ga_data)[stack->ga_len] = &t_number;
++stack->ga_len;
@@ -2431,7 +2431,7 @@
return NULL;
}
- if (ga_grow(&cctx->ctx_locals, 1) == FAIL)
+ if (GA_GROW_FAILS(&cctx->ctx_locals, 1))
return NULL;
lvar = ((lvar_T *)cctx->ctx_locals.ga_data) + cctx->ctx_locals.ga_len++;
CLEAR_POINTER(lvar);
@@ -2448,7 +2448,7 @@
lvar->lv_type = type;
// Remember the name for debugging.
- if (ga_grow(&dfunc->df_var_names, 1) == FAIL)
+ if (GA_GROW_FAILS(&dfunc->df_var_names, 1))
return NULL;
((char_u **)dfunc->df_var_names.ga_data)[lvar->lv_idx] =
vim_strsave(lvar->lv_name);
@@ -3280,7 +3280,7 @@
trailing_error = *s != NUL;
if (expr_res == FAIL || trailing_error
- || ga_grow(&cctx->ctx_instr, 1) == FAIL)
+ || GA_GROW_FAILS(&cctx->ctx_instr, 1))
{
if (trailing_error)
semsg(_(e_trailing_arg), s);
@@ -7034,7 +7034,7 @@
else
{
// variables are always initialized
- if (ga_grow(instr, 1) == FAIL)
+ if (GA_GROW_FAILS(instr, 1))
goto theend;
switch (lhs.lhs_member_type->tt_type)
{
@@ -7653,7 +7653,7 @@
// Move any CMDMOD instruction to after the jump
if (((isn_T *)instr->ga_data)[instr->ga_len - 1].isn_type == ISN_CMDMOD)
{
- if (ga_grow(instr, 1) == FAIL)
+ if (GA_GROW_FAILS(instr, 1))
return NULL;
((isn_T *)instr->ga_data)[instr->ga_len] =
((isn_T *)instr->ga_data)[instr->ga_len - 1];
@@ -7999,7 +7999,7 @@
arg = skipwhite(arg + 1); // skip white after '['
// the list item is replaced by a number of items
- if (ga_grow(stack, var_count - 1) == FAIL)
+ if (GA_GROW_FAILS(stack, var_count - 1))
{
drop_scope(cctx);
return NULL;
@@ -9107,7 +9107,7 @@
trailing_error = *cmd != delimiter && *cmd != NUL;
if (expr_res == FAIL || trailing_error
- || ga_grow(&cctx->ctx_instr, 1) == FAIL)
+ || GA_GROW_FAILS(&cctx->ctx_instr, 1))
{
if (trailing_error)
semsg(_(e_trailing_arg), cmd);
@@ -9267,13 +9267,13 @@
{
// The first position is not used, so that a zero uf_dfunc_idx means it
// wasn't set.
- if (ga_grow(&def_functions, 1) == FAIL)
+ if (GA_GROW_FAILS(&def_functions, 1))
return FAIL;
++def_functions.ga_len;
}
// Add the function to "def_functions".
- if (ga_grow(&def_functions, 1) == FAIL)
+ if (GA_GROW_FAILS(&def_functions, 1))
return FAIL;
dfunc = ((dfunc_T *)def_functions.ga_data) + def_functions.ga_len;
CLEAR_POINTER(dfunc);