Mercurial > vim
comparison src/vim9execute.c @ 20409:fd1b6f4f497e v8.2.0759
patch 8.2.0759: Vim9: missing changes for performance improvements
Commit: https://github.com/vim/vim/commit/270d0388d284c130b322b185497e437cfbbae412
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri May 15 21:42:53 2020 +0200
patch 8.2.0759: Vim9: missing changes for performance improvements
Problem: Vim9: missing changes for performance improvements
Solution: Use GA_GROW(). Don't call breakcheck so often.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 15 May 2020 21:45:03 +0200 |
parents | a8a76fd967ab |
children | 23af9e1a5283 |
comparison
equal
deleted
inserted
replaced
20408:f56e1311790e | 20409:fd1b6f4f497e |
---|---|
126 for (idx = 0; idx < count; ++idx) | 126 for (idx = 0; idx < count; ++idx) |
127 list_set_item(list, idx, STACK_TV_BOT(idx - count)); | 127 list_set_item(list, idx, STACK_TV_BOT(idx - count)); |
128 | 128 |
129 if (count > 0) | 129 if (count > 0) |
130 ectx->ec_stack.ga_len -= count - 1; | 130 ectx->ec_stack.ga_len -= count - 1; |
131 else if (ga_grow(&ectx->ec_stack, 1) == FAIL) | 131 else if (GA_GROW(&ectx->ec_stack, 1) == FAIL) |
132 return FAIL; | 132 return FAIL; |
133 else | 133 else |
134 ++ectx->ec_stack.ga_len; | 134 ++ectx->ec_stack.ga_len; |
135 tv = STACK_TV_BOT(-1); | 135 tv = STACK_TV_BOT(-1); |
136 tv->v_type = VAR_LIST; | 136 tv->v_type = VAR_LIST; |
435 argvars[argcount].v_type = VAR_UNKNOWN; | 435 argvars[argcount].v_type = VAR_UNKNOWN; |
436 | 436 |
437 // Result replaces the arguments on the stack. | 437 // Result replaces the arguments on the stack. |
438 if (argcount > 0) | 438 if (argcount > 0) |
439 ectx->ec_stack.ga_len -= argcount - 1; | 439 ectx->ec_stack.ga_len -= argcount - 1; |
440 else if (ga_grow(&ectx->ec_stack, 1) == FAIL) | 440 else if (GA_GROW(&ectx->ec_stack, 1) == FAIL) |
441 return FAIL; | 441 return FAIL; |
442 else | 442 else |
443 ++ectx->ec_stack.ga_len; | 443 ++ectx->ec_stack.ga_len; |
444 | 444 |
445 // Default return value is zero. | 445 // Default return value is zero. |
649 typval_T *tv; | 649 typval_T *tv; |
650 int idx; | 650 int idx; |
651 int ret = FAIL; | 651 int ret = FAIL; |
652 int defcount = ufunc->uf_args.ga_len - argc; | 652 int defcount = ufunc->uf_args.ga_len - argc; |
653 int save_sc_version = current_sctx.sc_version; | 653 int save_sc_version = current_sctx.sc_version; |
654 int breakcheck_count = 0; | |
654 | 655 |
655 // Get pointer to item in the stack. | 656 // Get pointer to item in the stack. |
656 #define STACK_TV(idx) (((typval_T *)ectx.ec_stack.ga_data) + idx) | 657 #define STACK_TV(idx) (((typval_T *)ectx.ec_stack.ga_data) + idx) |
657 | 658 |
658 // Get pointer to item at the bottom of the stack, -1 is the bottom. | 659 // Get pointer to item at the bottom of the stack, -1 is the bottom. |
747 | 748 |
748 for (;;) | 749 for (;;) |
749 { | 750 { |
750 isn_T *iptr; | 751 isn_T *iptr; |
751 | 752 |
752 veryfast_breakcheck(); | 753 if (++breakcheck_count >= 100) |
754 { | |
755 line_breakcheck(); | |
756 breakcheck_count = 0; | |
757 } | |
753 if (got_int) | 758 if (got_int) |
754 { | 759 { |
755 // Turn CTRL-C into an exception. | 760 // Turn CTRL-C into an exception. |
756 got_int = FALSE; | 761 got_int = FALSE; |
757 if (throw_exception("Vim:Interrupt", ET_INTERRUPT, NULL) == FAIL) | 762 if (throw_exception("Vim:Interrupt", ET_INTERRUPT, NULL) == FAIL) |
788 { | 793 { |
789 // not inside try or need to return from current functions. | 794 // not inside try or need to return from current functions. |
790 if (ectx.ec_frame_idx == initial_frame_idx) | 795 if (ectx.ec_frame_idx == initial_frame_idx) |
791 { | 796 { |
792 // At the toplevel we are done. Push a dummy return value. | 797 // At the toplevel we are done. Push a dummy return value. |
793 if (ga_grow(&ectx.ec_stack, 1) == FAIL) | 798 if (GA_GROW(&ectx.ec_stack, 1) == FAIL) |
794 goto failed; | 799 goto failed; |
795 tv = STACK_TV_BOT(0); | 800 tv = STACK_TV_BOT(0); |
796 tv->v_type = VAR_NUMBER; | 801 tv->v_type = VAR_NUMBER; |
797 tv->vval.v_number = 0; | 802 tv->vval.v_number = 0; |
798 ++ectx.ec_stack.ga_len; | 803 ++ectx.ec_stack.ga_len; |
940 } | 945 } |
941 break; | 946 break; |
942 | 947 |
943 // load local variable or argument | 948 // load local variable or argument |
944 case ISN_LOAD: | 949 case ISN_LOAD: |
945 if (ga_grow(&ectx.ec_stack, 1) == FAIL) | 950 if (GA_GROW(&ectx.ec_stack, 1) == FAIL) |
946 goto failed; | 951 goto failed; |
947 copy_tv(STACK_TV_VAR(iptr->isn_arg.number), STACK_TV_BOT(0)); | 952 copy_tv(STACK_TV_VAR(iptr->isn_arg.number), STACK_TV_BOT(0)); |
948 ++ectx.ec_stack.ga_len; | 953 ++ectx.ec_stack.ga_len; |
949 break; | 954 break; |
950 | 955 |
951 // load variable or argument from outer scope | 956 // load variable or argument from outer scope |
952 case ISN_LOADOUTER: | 957 case ISN_LOADOUTER: |
953 if (ga_grow(&ectx.ec_stack, 1) == FAIL) | 958 if (GA_GROW(&ectx.ec_stack, 1) == FAIL) |
954 goto failed; | 959 goto failed; |
955 copy_tv(STACK_OUT_TV_VAR(iptr->isn_arg.number), | 960 copy_tv(STACK_OUT_TV_VAR(iptr->isn_arg.number), |
956 STACK_TV_BOT(0)); | 961 STACK_TV_BOT(0)); |
957 ++ectx.ec_stack.ga_len; | 962 ++ectx.ec_stack.ga_len; |
958 break; | 963 break; |
959 | 964 |
960 // load v: variable | 965 // load v: variable |
961 case ISN_LOADV: | 966 case ISN_LOADV: |
962 if (ga_grow(&ectx.ec_stack, 1) == FAIL) | 967 if (GA_GROW(&ectx.ec_stack, 1) == FAIL) |
963 goto failed; | 968 goto failed; |
964 copy_tv(get_vim_var_tv(iptr->isn_arg.number), STACK_TV_BOT(0)); | 969 copy_tv(get_vim_var_tv(iptr->isn_arg.number), STACK_TV_BOT(0)); |
965 ++ectx.ec_stack.ga_len; | 970 ++ectx.ec_stack.ga_len; |
966 break; | 971 break; |
967 | 972 |
972 SCRIPT_ITEM(iptr->isn_arg.script.script_sid); | 977 SCRIPT_ITEM(iptr->isn_arg.script.script_sid); |
973 svar_T *sv; | 978 svar_T *sv; |
974 | 979 |
975 sv = ((svar_T *)si->sn_var_vals.ga_data) | 980 sv = ((svar_T *)si->sn_var_vals.ga_data) |
976 + iptr->isn_arg.script.script_idx; | 981 + iptr->isn_arg.script.script_idx; |
977 if (ga_grow(&ectx.ec_stack, 1) == FAIL) | 982 if (GA_GROW(&ectx.ec_stack, 1) == FAIL) |
978 goto failed; | 983 goto failed; |
979 copy_tv(sv->sv_tv, STACK_TV_BOT(0)); | 984 copy_tv(sv->sv_tv, STACK_TV_BOT(0)); |
980 ++ectx.ec_stack.ga_len; | 985 ++ectx.ec_stack.ga_len; |
981 } | 986 } |
982 break; | 987 break; |
994 semsg(_(e_undefvar), name); | 999 semsg(_(e_undefvar), name); |
995 goto failed; | 1000 goto failed; |
996 } | 1001 } |
997 else | 1002 else |
998 { | 1003 { |
999 if (ga_grow(&ectx.ec_stack, 1) == FAIL) | 1004 if (GA_GROW(&ectx.ec_stack, 1) == FAIL) |
1000 goto failed; | 1005 goto failed; |
1001 copy_tv(&di->di_tv, STACK_TV_BOT(0)); | 1006 copy_tv(&di->di_tv, STACK_TV_BOT(0)); |
1002 ++ectx.ec_stack.ga_len; | 1007 ++ectx.ec_stack.ga_len; |
1003 } | 1008 } |
1004 } | 1009 } |
1042 namespace, iptr->isn_arg.string); | 1047 namespace, iptr->isn_arg.string); |
1043 goto failed; | 1048 goto failed; |
1044 } | 1049 } |
1045 else | 1050 else |
1046 { | 1051 { |
1047 if (ga_grow(&ectx.ec_stack, 1) == FAIL) | 1052 if (GA_GROW(&ectx.ec_stack, 1) == FAIL) |
1048 goto failed; | 1053 goto failed; |
1049 copy_tv(&di->di_tv, STACK_TV_BOT(0)); | 1054 copy_tv(&di->di_tv, STACK_TV_BOT(0)); |
1050 ++ectx.ec_stack.ga_len; | 1055 ++ectx.ec_stack.ga_len; |
1051 } | 1056 } |
1052 } | 1057 } |
1058 typval_T optval; | 1063 typval_T optval; |
1059 char_u *name = iptr->isn_arg.string; | 1064 char_u *name = iptr->isn_arg.string; |
1060 | 1065 |
1061 // This is not expected to fail, name is checked during | 1066 // This is not expected to fail, name is checked during |
1062 // compilation: don't set SOURCING_LNUM. | 1067 // compilation: don't set SOURCING_LNUM. |
1063 if (ga_grow(&ectx.ec_stack, 1) == FAIL) | 1068 if (GA_GROW(&ectx.ec_stack, 1) == FAIL) |
1064 goto failed; | 1069 goto failed; |
1065 if (get_option_tv(&name, &optval, TRUE) == FAIL) | 1070 if (get_option_tv(&name, &optval, TRUE) == FAIL) |
1066 goto failed; | 1071 goto failed; |
1067 *STACK_TV_BOT(0) = optval; | 1072 *STACK_TV_BOT(0) = optval; |
1068 ++ectx.ec_stack.ga_len; | 1073 ++ectx.ec_stack.ga_len; |
1073 case ISN_LOADENV: | 1078 case ISN_LOADENV: |
1074 { | 1079 { |
1075 typval_T optval; | 1080 typval_T optval; |
1076 char_u *name = iptr->isn_arg.string; | 1081 char_u *name = iptr->isn_arg.string; |
1077 | 1082 |
1078 if (ga_grow(&ectx.ec_stack, 1) == FAIL) | 1083 if (GA_GROW(&ectx.ec_stack, 1) == FAIL) |
1079 goto failed; | 1084 goto failed; |
1080 // name is always valid, checked when compiling | 1085 // name is always valid, checked when compiling |
1081 (void)get_env_tv(&name, &optval, TRUE); | 1086 (void)get_env_tv(&name, &optval, TRUE); |
1082 *STACK_TV_BOT(0) = optval; | 1087 *STACK_TV_BOT(0) = optval; |
1083 ++ectx.ec_stack.ga_len; | 1088 ++ectx.ec_stack.ga_len; |
1084 } | 1089 } |
1085 break; | 1090 break; |
1086 | 1091 |
1087 // load @register | 1092 // load @register |
1088 case ISN_LOADREG: | 1093 case ISN_LOADREG: |
1089 if (ga_grow(&ectx.ec_stack, 1) == FAIL) | 1094 if (GA_GROW(&ectx.ec_stack, 1) == FAIL) |
1090 goto failed; | 1095 goto failed; |
1091 tv = STACK_TV_BOT(0); | 1096 tv = STACK_TV_BOT(0); |
1092 tv->v_type = VAR_STRING; | 1097 tv->v_type = VAR_STRING; |
1093 tv->vval.v_string = get_reg_contents( | 1098 tv->vval.v_string = get_reg_contents( |
1094 iptr->isn_arg.number, GREG_EXPR_SRC); | 1099 iptr->isn_arg.number, GREG_EXPR_SRC); |
1332 case ISN_PUSHS: | 1337 case ISN_PUSHS: |
1333 case ISN_PUSHBLOB: | 1338 case ISN_PUSHBLOB: |
1334 case ISN_PUSHFUNC: | 1339 case ISN_PUSHFUNC: |
1335 case ISN_PUSHCHANNEL: | 1340 case ISN_PUSHCHANNEL: |
1336 case ISN_PUSHJOB: | 1341 case ISN_PUSHJOB: |
1337 if (ga_grow(&ectx.ec_stack, 1) == FAIL) | 1342 if (GA_GROW(&ectx.ec_stack, 1) == FAIL) |
1338 goto failed; | 1343 goto failed; |
1339 tv = STACK_TV_BOT(0); | 1344 tv = STACK_TV_BOT(0); |
1340 ++ectx.ec_stack.ga_len; | 1345 ++ectx.ec_stack.ga_len; |
1341 switch (iptr->isn_type) | 1346 switch (iptr->isn_type) |
1342 { | 1347 { |
1432 goto failed; | 1437 goto failed; |
1433 } | 1438 } |
1434 | 1439 |
1435 if (count > 0) | 1440 if (count > 0) |
1436 ectx.ec_stack.ga_len -= 2 * count - 1; | 1441 ectx.ec_stack.ga_len -= 2 * count - 1; |
1437 else if (ga_grow(&ectx.ec_stack, 1) == FAIL) | 1442 else if (GA_GROW(&ectx.ec_stack, 1) == FAIL) |
1438 goto failed; | 1443 goto failed; |
1439 else | 1444 else |
1440 ++ectx.ec_stack.ga_len; | 1445 ++ectx.ec_stack.ga_len; |
1441 tv = STACK_TV_BOT(-1); | 1446 tv = STACK_TV_BOT(-1); |
1442 tv->v_type = VAR_DICT; | 1447 tv->v_type = VAR_DICT; |
1552 dfunc_T *pt_dfunc; | 1557 dfunc_T *pt_dfunc; |
1553 | 1558 |
1554 pt = ALLOC_CLEAR_ONE(partial_T); | 1559 pt = ALLOC_CLEAR_ONE(partial_T); |
1555 if (pt == NULL) | 1560 if (pt == NULL) |
1556 goto failed; | 1561 goto failed; |
1557 if (ga_grow(&ectx.ec_stack, 1) == FAIL) | 1562 if (GA_GROW(&ectx.ec_stack, 1) == FAIL) |
1558 { | 1563 { |
1559 vim_free(pt); | 1564 vim_free(pt); |
1560 goto failed; | 1565 goto failed; |
1561 } | 1566 } |
1562 pt_dfunc = ((dfunc_T *)def_functions.ga_data) | 1567 pt_dfunc = ((dfunc_T *)def_functions.ga_data) |
1630 list_T *list = STACK_TV_BOT(-1)->vval.v_list; | 1635 list_T *list = STACK_TV_BOT(-1)->vval.v_list; |
1631 typval_T *idxtv = | 1636 typval_T *idxtv = |
1632 STACK_TV_VAR(iptr->isn_arg.forloop.for_idx); | 1637 STACK_TV_VAR(iptr->isn_arg.forloop.for_idx); |
1633 | 1638 |
1634 // push the next item from the list | 1639 // push the next item from the list |
1635 if (ga_grow(&ectx.ec_stack, 1) == FAIL) | 1640 if (GA_GROW(&ectx.ec_stack, 1) == FAIL) |
1636 goto failed; | 1641 goto failed; |
1637 if (++idxtv->vval.v_number >= list->lv_len) | 1642 if (++idxtv->vval.v_number >= list->lv_len) |
1638 // past the end of the list, jump to "endfor" | 1643 // past the end of the list, jump to "endfor" |
1639 ectx.ec_iidx = iptr->isn_arg.forloop.for_end; | 1644 ectx.ec_iidx = iptr->isn_arg.forloop.for_end; |
1640 else if (list->lv_first == &range_list_item) | 1645 else if (list->lv_first == &range_list_item) |
1661 // start of ":try" block | 1666 // start of ":try" block |
1662 case ISN_TRY: | 1667 case ISN_TRY: |
1663 { | 1668 { |
1664 trycmd_T *trycmd = NULL; | 1669 trycmd_T *trycmd = NULL; |
1665 | 1670 |
1666 if (ga_grow(&ectx.ec_trystack, 1) == FAIL) | 1671 if (GA_GROW(&ectx.ec_trystack, 1) == FAIL) |
1667 goto failed; | 1672 goto failed; |
1668 trycmd = ((trycmd_T *)ectx.ec_trystack.ga_data) | 1673 trycmd = ((trycmd_T *)ectx.ec_trystack.ga_data) |
1669 + ectx.ec_trystack.ga_len; | 1674 + ectx.ec_trystack.ga_len; |
1670 ++ectx.ec_trystack.ga_len; | 1675 ++ectx.ec_trystack.ga_len; |
1671 ++trylevel; | 1676 ++trylevel; |
1680 if (current_exception == NULL) | 1685 if (current_exception == NULL) |
1681 { | 1686 { |
1682 iemsg("Evaluating catch while current_exception is NULL"); | 1687 iemsg("Evaluating catch while current_exception is NULL"); |
1683 goto failed; | 1688 goto failed; |
1684 } | 1689 } |
1685 if (ga_grow(&ectx.ec_stack, 1) == FAIL) | 1690 if (GA_GROW(&ectx.ec_stack, 1) == FAIL) |
1686 goto failed; | 1691 goto failed; |
1687 tv = STACK_TV_BOT(0); | 1692 tv = STACK_TV_BOT(0); |
1688 ++ectx.ec_stack.ga_len; | 1693 ++ectx.ec_stack.ga_len; |
1689 tv->v_type = VAR_STRING; | 1694 tv->v_type = VAR_STRING; |
1690 tv->vval.v_string = vim_strsave( | 1695 tv->vval.v_string = vim_strsave( |