Mercurial > vim
diff src/vim9compile.c @ 25477:a8f526c9b172 v8.2.3275
patch 8.2.3275: optimizer can use hints about ga_grow() normally succeeding
Commit: https://github.com/vim/vim/commit/35578168becd1e11973bec413f2078a4bf81ba6b
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Aug 2 19:10:38 2021 +0200
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)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 02 Aug 2021 19:15:03 +0200 |
parents | dcd45fe7fe2e |
children | fbdfa533001c |
line wrap: on
line diff
--- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -548,7 +548,7 @@ generate_instr(cctx_T *cctx, isntype_T i 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 @@ generate_instr_type(cctx_T *cctx, isntyp 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 @@ generate_GETITEM(cctx_T *cctx, int index 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 @@ generate_NEWLIST(cctx_T *cctx, int count 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 @@ generate_NEWDICT(cctx_T *cctx, int count 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 @@ generate_FUNCREF(cctx_T *cctx, ufunc_T * 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 @@ generate_FOR(cctx_T *cctx, int loop_idx) 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 @@ generate_BCALL(cctx_T *cctx, int func_id // 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 @@ generate_CALL(cctx_T *cctx, ufunc_T *ufu } 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 @@ generate_UCALL(cctx_T *cctx, char_u *nam 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 @@ generate_LEGACY_EVAL(cctx_T *cctx, char_ 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 @@ generate_RANGE(cctx_T *cctx, char_u *ran 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 @@ reserve_local( 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 @@ reserve_local( 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 @@ compile_string(isn_T *isn, cctx_T *cctx) 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 @@ compile_assignment(char_u *arg, exarg_T 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 @@ compile_elseif(char_u *arg, cctx_T *cctx // 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 @@ compile_for(char_u *arg_start, cctx_T *c 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 @@ compile_substitute(char_u *arg, exarg_T 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 @@ add_def_function(ufunc_T *ufunc) { // 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);