Mercurial > vim
comparison src/map.c @ 28600:17251b82b69a v8.2.4824
patch 8.2.4824: expression is evaluated multiple times
Commit: https://github.com/vim/vim/commit/23d5770ef5e2f5c6d20d123303b81327045e5a1e
Author: zeertzjq <zeertzjq@outlook.com>
Date: Mon Apr 25 13:28:00 2022 +0100
patch 8.2.4824: expression is evaluated multiple times
Problem: Expression is evaluated multiple times.
Solution: Evaluate expression once and store the result. (closes https://github.com/vim/vim/issues/10278)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 25 Apr 2022 14:30:03 +0200 |
parents | d3c966c0cdf7 |
children | 398c5b3211f9 |
comparison
equal
deleted
inserted
replaced
28599:21b38da3ec22 | 28600:17251b82b69a |
---|---|
506 */ | 506 */ |
507 for (keyround = 1; keyround <= 2; ++keyround) | 507 for (keyround = 1; keyround <= 2; ++keyround) |
508 { | 508 { |
509 int did_it = FALSE; | 509 int did_it = FALSE; |
510 int did_local = FALSE; | 510 int did_local = FALSE; |
511 int keyround1_simplfied = keyround == 1 && did_simplify; | |
511 int round; | 512 int round; |
512 int hash; | 513 int hash; |
513 int new_hash; | 514 int new_hash; |
514 | 515 |
515 if (keyround == 2) | 516 if (keyround == 2) |
723 || *skipwhite(keys + n) != NUL)) | 724 || *skipwhite(keys + n) != NUL)) |
724 { | 725 { |
725 mpp = &(mp->m_next); | 726 mpp = &(mp->m_next); |
726 continue; | 727 continue; |
727 } | 728 } |
728 if (did_simplify && keyround == 1 | 729 if (keyround1_simplfied && !mp->m_simplified) |
729 && !mp->m_simplified) | |
730 break; | 730 break; |
731 // We reset the indicated mode bits. If nothing | 731 // We reset the indicated mode bits. If nothing |
732 // is left the entry is deleted below. | 732 // is left the entry is deleted below. |
733 mp->m_mode &= ~mode; | 733 mp->m_mode &= ~mode; |
734 did_it = TRUE; // remember we did something | 734 did_it = TRUE; // remember we did something |
777 mp->m_orig_str = vim_strsave(orig_rhs); | 777 mp->m_orig_str = vim_strsave(orig_rhs); |
778 mp->m_noremap = noremap; | 778 mp->m_noremap = noremap; |
779 mp->m_nowait = nowait; | 779 mp->m_nowait = nowait; |
780 mp->m_silent = silent; | 780 mp->m_silent = silent; |
781 mp->m_mode = mode; | 781 mp->m_mode = mode; |
782 mp->m_simplified = | 782 mp->m_simplified = keyround1_simplfied; |
783 did_simplify && keyround == 1; | |
784 #ifdef FEAT_EVAL | 783 #ifdef FEAT_EVAL |
785 mp->m_expr = expr; | 784 mp->m_expr = expr; |
786 mp->m_script_ctx = current_sctx; | 785 mp->m_script_ctx = current_sctx; |
787 mp->m_script_ctx.sc_lnum += SOURCING_LNUM; | 786 mp->m_script_ctx.sc_lnum += SOURCING_LNUM; |
788 #endif | 787 #endif |
816 if (maptype == 1) | 815 if (maptype == 1) |
817 { | 816 { |
818 // delete entry | 817 // delete entry |
819 if (!did_it) | 818 if (!did_it) |
820 { | 819 { |
821 if (!did_simplify || keyround == 2) | 820 if (!keyround1_simplfied) |
822 retval = 2; // no match | 821 retval = 2; // no match |
823 } | 822 } |
824 else if (*keys == Ctrl_C) | 823 else if (*keys == Ctrl_C) |
825 { | 824 { |
826 // If CTRL-C has been unmapped, reuse it for Interrupting. | 825 // If CTRL-C has been unmapped, reuse it for Interrupting. |
852 if (map_add(map_table, abbr_table, keys, rhs, orig_rhs, | 851 if (map_add(map_table, abbr_table, keys, rhs, orig_rhs, |
853 noremap, nowait, silent, mode, abbrev, | 852 noremap, nowait, silent, mode, abbrev, |
854 #ifdef FEAT_EVAL | 853 #ifdef FEAT_EVAL |
855 expr, /* sid */ -1, /* scriptversion */ 0, /* lnum */ 0, | 854 expr, /* sid */ -1, /* scriptversion */ 0, /* lnum */ 0, |
856 #endif | 855 #endif |
857 did_simplify && keyround == 1) == FAIL) | 856 keyround1_simplfied) == FAIL) |
858 { | 857 { |
859 retval = 4; // no mem | 858 retval = 4; // no mem |
860 goto theend; | 859 goto theend; |
861 } | 860 } |
862 } | 861 } |