Mercurial > vim
comparison src/vim9execute.c @ 26644:2fc1e528e0e1 v8.2.3851
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Commit: https://github.com/vim/vim/commit/265f811f5a2dac81d9698f5202a661a04ed095f1
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Dec 19 12:33:05 2021 +0000
patch 8.2.3851: Vim9: overhead when comparing string, dict or function
Problem: Vim9: overhead when comparing string, dict or function.
Solution: Call the intented compare function directly. Refactor to avoid
duplicated code.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 19 Dec 2021 13:45:03 +0100 |
parents | 4d18b3a5254a |
children | 4b23672d1f0e |
comparison
equal
deleted
inserted
replaced
26643:c1613719988c | 26644:2fc1e528e0e1 |
---|---|
3807 } | 3807 } |
3808 #endif | 3808 #endif |
3809 break; | 3809 break; |
3810 | 3810 |
3811 case ISN_COMPARELIST: | 3811 case ISN_COMPARELIST: |
3812 case ISN_COMPAREDICT: | |
3813 case ISN_COMPAREFUNC: | |
3814 case ISN_COMPARESTRING: | |
3815 case ISN_COMPAREBLOB: | |
3812 { | 3816 { |
3813 typval_T *tv1 = STACK_TV_BOT(-2); | 3817 typval_T *tv1 = STACK_TV_BOT(-2); |
3814 typval_T *tv2 = STACK_TV_BOT(-1); | 3818 typval_T *tv2 = STACK_TV_BOT(-1); |
3815 list_T *arg1 = tv1->vval.v_list; | 3819 exprtype_T exprtype = iptr->isn_arg.op.op_type; |
3816 list_T *arg2 = tv2->vval.v_list; | |
3817 int cmp = FALSE; | |
3818 int ic = iptr->isn_arg.op.op_ic; | 3820 int ic = iptr->isn_arg.op.op_ic; |
3819 | 3821 int res = FALSE; |
3820 switch (iptr->isn_arg.op.op_type) | 3822 int status = OK; |
3821 { | 3823 |
3822 case EXPR_EQUAL: cmp = | 3824 SOURCING_LNUM = iptr->isn_lnum; |
3823 list_equal(arg1, arg2, ic, FALSE); break; | 3825 if (iptr->isn_type == ISN_COMPARELIST) |
3824 case EXPR_NEQUAL: cmp = | 3826 { |
3825 !list_equal(arg1, arg2, ic, FALSE); break; | 3827 status = typval_compare_list(tv1, tv2, |
3826 case EXPR_IS: cmp = arg1 == arg2; break; | 3828 exprtype, ic, &res); |
3827 case EXPR_ISNOT: cmp = arg1 != arg2; break; | 3829 } |
3828 default: cmp = 0; break; | 3830 else if (iptr->isn_type == ISN_COMPAREDICT) |
3831 { | |
3832 status = typval_compare_dict(tv1, tv2, | |
3833 exprtype, ic, &res); | |
3834 } | |
3835 else if (iptr->isn_type == ISN_COMPAREFUNC) | |
3836 { | |
3837 status = typval_compare_func(tv1, tv2, | |
3838 exprtype, ic, &res); | |
3839 } | |
3840 else if (iptr->isn_type == ISN_COMPARESTRING) | |
3841 { | |
3842 status = typval_compare_string(tv1, tv2, | |
3843 exprtype, ic, &res); | |
3844 } | |
3845 else | |
3846 { | |
3847 status = typval_compare_blob(tv1, tv2, exprtype, &res); | |
3829 } | 3848 } |
3830 --ectx->ec_stack.ga_len; | 3849 --ectx->ec_stack.ga_len; |
3831 clear_tv(tv1); | 3850 clear_tv(tv1); |
3832 clear_tv(tv2); | 3851 clear_tv(tv2); |
3833 tv1->v_type = VAR_BOOL; | 3852 tv1->v_type = VAR_BOOL; |
3834 tv1->vval.v_number = cmp ? VVAL_TRUE : VVAL_FALSE; | 3853 tv1->vval.v_number = res ? VVAL_TRUE : VVAL_FALSE; |
3835 } | 3854 if (status == FAIL) |
3836 break; | 3855 goto theend; |
3837 | 3856 } |
3838 case ISN_COMPAREBLOB: | 3857 break; |
3839 { | 3858 |
3840 typval_T *tv1 = STACK_TV_BOT(-2); | |
3841 typval_T *tv2 = STACK_TV_BOT(-1); | |
3842 blob_T *arg1 = tv1->vval.v_blob; | |
3843 blob_T *arg2 = tv2->vval.v_blob; | |
3844 int cmp = FALSE; | |
3845 | |
3846 switch (iptr->isn_arg.op.op_type) | |
3847 { | |
3848 case EXPR_EQUAL: cmp = blob_equal(arg1, arg2); break; | |
3849 case EXPR_NEQUAL: cmp = !blob_equal(arg1, arg2); break; | |
3850 case EXPR_IS: cmp = arg1 == arg2; break; | |
3851 case EXPR_ISNOT: cmp = arg1 != arg2; break; | |
3852 default: cmp = 0; break; | |
3853 } | |
3854 --ectx->ec_stack.ga_len; | |
3855 clear_tv(tv1); | |
3856 clear_tv(tv2); | |
3857 tv1->v_type = VAR_BOOL; | |
3858 tv1->vval.v_number = cmp ? VVAL_TRUE : VVAL_FALSE; | |
3859 } | |
3860 break; | |
3861 | |
3862 // TODO: handle separately | |
3863 case ISN_COMPARESTRING: | |
3864 case ISN_COMPAREDICT: | |
3865 case ISN_COMPAREFUNC: | |
3866 case ISN_COMPAREANY: | 3859 case ISN_COMPAREANY: |
3867 { | 3860 { |
3868 typval_T *tv1 = STACK_TV_BOT(-2); | 3861 typval_T *tv1 = STACK_TV_BOT(-2); |
3869 typval_T *tv2 = STACK_TV_BOT(-1); | 3862 typval_T *tv2 = STACK_TV_BOT(-1); |
3870 exprtype_T exprtype = iptr->isn_arg.op.op_type; | 3863 exprtype_T exprtype = iptr->isn_arg.op.op_type; |
3871 int ic = iptr->isn_arg.op.op_ic; | 3864 int ic = iptr->isn_arg.op.op_ic; |
3865 int status; | |
3872 | 3866 |
3873 SOURCING_LNUM = iptr->isn_lnum; | 3867 SOURCING_LNUM = iptr->isn_lnum; |
3874 typval_compare(tv1, tv2, exprtype, ic); | 3868 status = typval_compare(tv1, tv2, exprtype, ic); |
3875 clear_tv(tv2); | 3869 clear_tv(tv2); |
3876 --ectx->ec_stack.ga_len; | 3870 --ectx->ec_stack.ga_len; |
3871 if (status == FAIL) | |
3872 goto theend; | |
3877 } | 3873 } |
3878 break; | 3874 break; |
3879 | 3875 |
3880 case ISN_ADDLIST: | 3876 case ISN_ADDLIST: |
3881 case ISN_ADDBLOB: | 3877 case ISN_ADDBLOB: |