comparison src/evalfunc.c @ 20392:4c317d8c1051 v8.2.0751

patch 8.2.0751: Vim9: performance can be improved Commit: https://github.com/vim/vim/commit/7e9f351b2e69b498c4ee5004d7459844e1ba191a Author: Bram Moolenaar <Bram@vim.org> Date: Wed May 13 22:44:22 2020 +0200 patch 8.2.0751: Vim9: performance can be improved Problem: Vim9: performance can be improved. Solution: Don't call break. Inline check for list materialize. Make an inline version of ga_grow().
author Bram Moolenaar <Bram@vim.org>
date Wed, 13 May 2020 22:45:04 +0200
parents 3b3589275ab9
children c225be44692a
comparison
equal deleted inserted replaced
20391:9ceee4daa596 20392:4c317d8c1051
2273 do_cmdline_cmd(cmd); 2273 do_cmdline_cmd(cmd);
2274 else 2274 else
2275 { 2275 {
2276 listitem_T *item; 2276 listitem_T *item;
2277 2277
2278 range_list_materialize(list); 2278 CHECK_LIST_MATERIALIZE(list);
2279 item = list->lv_first; 2279 item = list->lv_first;
2280 do_cmdline(NULL, get_list_line, (void *)&item, 2280 do_cmdline(NULL, get_list_line, (void *)&item,
2281 DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT|DOCMD_KEYTYPED); 2281 DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT|DOCMD_KEYTYPED);
2282 --list->lv_refcount; 2282 --list->lv_refcount;
2283 } 2283 }
2818 } 2818 }
2819 for (i = 0; i < arg_len; i++) 2819 for (i = 0; i < arg_len; i++)
2820 copy_tv(&arg_pt->pt_argv[i], &pt->pt_argv[i]); 2820 copy_tv(&arg_pt->pt_argv[i], &pt->pt_argv[i]);
2821 if (lv_len > 0) 2821 if (lv_len > 0)
2822 { 2822 {
2823 range_list_materialize(list); 2823 CHECK_LIST_MATERIALIZE(list);
2824 FOR_ALL_LIST_ITEMS(list, li) 2824 FOR_ALL_LIST_ITEMS(list, li)
2825 copy_tv(&li->li_tv, &pt->pt_argv[i++]); 2825 copy_tv(&li->li_tv, &pt->pt_argv[i++]);
2826 } 2826 }
2827 } 2827 }
2828 2828
4910 } 4910 }
4911 4911
4912 l = argvars[0].vval.v_list; 4912 l = argvars[0].vval.v_list;
4913 if (l != NULL) 4913 if (l != NULL)
4914 { 4914 {
4915 range_list_materialize(l); 4915 CHECK_LIST_MATERIALIZE(l);
4916 item = l->lv_first; 4916 item = l->lv_first;
4917 if (argvars[2].v_type != VAR_UNKNOWN) 4917 if (argvars[2].v_type != VAR_UNKNOWN)
4918 { 4918 {
4919 // Start at specified item. Use the cached index that list_find() 4919 // Start at specified item. Use the cached index that list_find()
4920 // sets, so that a negative number also works. 4920 // sets, so that a negative number also works.
5016 lines_left = Rows; // avoid more prompt 5016 lines_left = Rows; // avoid more prompt
5017 msg_scroll = TRUE; 5017 msg_scroll = TRUE;
5018 msg_clr_eos(); 5018 msg_clr_eos();
5019 5019
5020 l = argvars[0].vval.v_list; 5020 l = argvars[0].vval.v_list;
5021 range_list_materialize(l); 5021 CHECK_LIST_MATERIALIZE(l);
5022 FOR_ALL_LIST_ITEMS(l, li) 5022 FOR_ALL_LIST_ITEMS(l, li)
5023 { 5023 {
5024 msg_puts((char *)tv_get_string(&li->li_tv)); 5024 msg_puts((char *)tv_get_string(&li->li_tv));
5025 msg_putchar('\n'); 5025 msg_putchar('\n');
5026 } 5026 }
5492 5492
5493 if (argvars[0].v_type == VAR_LIST) 5493 if (argvars[0].v_type == VAR_LIST)
5494 { 5494 {
5495 if ((l = argvars[0].vval.v_list) == NULL) 5495 if ((l = argvars[0].vval.v_list) == NULL)
5496 goto theend; 5496 goto theend;
5497 range_list_materialize(l); 5497 CHECK_LIST_MATERIALIZE(l);
5498 li = l->lv_first; 5498 li = l->lv_first;
5499 } 5499 }
5500 else 5500 else
5501 { 5501 {
5502 expr = str = tv_get_string(&argvars[0]); 5502 expr = str = tv_get_string(&argvars[0]);
6277 else if (rettv_list_alloc(rettv) == OK) 6277 else if (rettv_list_alloc(rettv) == OK)
6278 { 6278 {
6279 list_T *list = rettv->vval.v_list; 6279 list_T *list = rettv->vval.v_list;
6280 6280
6281 // Create a non-materialized list. This is much more efficient and 6281 // Create a non-materialized list. This is much more efficient and
6282 // works with ":for". If used otherwise range_list_materialize() must 6282 // works with ":for". If used otherwise CHECK_LIST_MATERIALIZE() must
6283 // be called. 6283 // be called.
6284 list->lv_first = &range_list_item; 6284 list->lv_first = &range_list_item;
6285 list->lv_u.nonmat.lv_start = start; 6285 list->lv_u.nonmat.lv_start = start;
6286 list->lv_u.nonmat.lv_end = end; 6286 list->lv_u.nonmat.lv_end = end;
6287 list->lv_u.nonmat.lv_stride = stride; 6287 list->lv_u.nonmat.lv_stride = stride;
6288 list->lv_len = (end - start) / stride + 1; 6288 list->lv_len = (end - start) / stride + 1;
6289 } 6289 }
6290 } 6290 }
6291 6291
6292 /* 6292 /*
6293 * If "list" is a non-materialized list then materialize it now. 6293 * Materialize "list".
6294 * Do not call directly, use CHECK_LIST_MATERIALIZE()
6294 */ 6295 */
6295 void 6296 void
6296 range_list_materialize(list_T *list) 6297 range_list_materialize(list_T *list)
6297 { 6298 {
6298 if (list->lv_first == &range_list_item) 6299 varnumber_T start = list->lv_u.nonmat.lv_start;
6299 { 6300 varnumber_T end = list->lv_u.nonmat.lv_end;
6300 varnumber_T start = list->lv_u.nonmat.lv_start; 6301 int stride = list->lv_u.nonmat.lv_stride;
6301 varnumber_T end = list->lv_u.nonmat.lv_end; 6302 varnumber_T i;
6302 int stride = list->lv_u.nonmat.lv_stride; 6303
6303 varnumber_T i; 6304 list->lv_first = NULL;
6304 6305 list->lv_u.mat.lv_last = NULL;
6305 list->lv_first = NULL; 6306 list->lv_len = 0;
6306 list->lv_u.mat.lv_last = NULL; 6307 list->lv_u.mat.lv_idx_item = NULL;
6307 list->lv_len = 0; 6308 for (i = start; stride > 0 ? i <= end : i >= end; i += stride)
6308 list->lv_u.mat.lv_idx_item = NULL; 6309 if (list_append_number(list, (varnumber_T)i) == FAIL)
6309 for (i = start; stride > 0 ? i <= end : i >= end; i += stride) 6310 break;
6310 if (list_append_number(list, (varnumber_T)i) == FAIL)
6311 break;
6312 }
6313 } 6311 }
6314 6312
6315 static void 6313 static void
6316 return_register(int regname, typval_T *rettv) 6314 return_register(int regname, typval_T *rettv)
6317 { 6315 {
7325 allocval = lstval + len + 2; 7323 allocval = lstval + len + 2;
7326 curallocval = allocval; 7324 curallocval = allocval;
7327 7325
7328 if (ll != NULL) 7326 if (ll != NULL)
7329 { 7327 {
7330 range_list_materialize(ll); 7328 CHECK_LIST_MATERIALIZE(ll);
7331 FOR_ALL_LIST_ITEMS(ll, li) 7329 FOR_ALL_LIST_ITEMS(ll, li)
7332 { 7330 {
7333 strval = tv_get_string_buf_chk(&li->li_tv, buf); 7331 strval = tv_get_string_buf_chk(&li->li_tv, buf);
7334 if (strval == NULL) 7332 if (strval == NULL)
7335 goto free_lstval; 7333 goto free_lstval;