From e38cddc98953c64a7c7cd01fb0841e41a8674727 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 27 Apr 2022 20:23:02 +0800 Subject: vim-patch:8.2.4824: expression is evaluated multiple times Problem: Expression is evaluated multiple times. Solution: Evaluate expression once and store the result. (closes vim/vim#10278) https://github.com/vim/vim/commit/23d5770ef5e2f5c6d20d123303b81327045e5a1e --- src/nvim/getchar.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 1fb3f827c1..61020ccf05 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -3074,6 +3074,7 @@ int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, buf_T for (int keyround = 1; keyround <= 2; keyround++) { bool did_it = false; bool did_local = false; + bool keyround1_simplfied = keyround == 1 && did_simplify; int len = (int)args->lhs_len; if (keyround == 2) { @@ -3248,7 +3249,7 @@ int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, buf_T mpp = &(mp->m_next); continue; } - if (did_simplify && keyround == 1 && !mp->m_simplified) { + if (keyround1_simplfied && !mp->m_simplified) { break; } // We reset the indicated mode bits. If nothing @@ -3287,7 +3288,7 @@ int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, buf_T mp->m_nowait = args->nowait; mp->m_silent = args->silent; mp->m_mode = mode; - mp->m_simplified = did_simplify && keyround == 1; + mp->m_simplified = keyround1_simplfied; mp->m_expr = args->expr; mp->m_script_ctx = current_sctx; mp->m_script_ctx.sc_lnum += sourcing_lnum; @@ -3322,7 +3323,7 @@ int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, buf_T if (maptype == 1) { // delete entry if (!did_it) { - if (!did_simplify || keyround == 2) { + if (!keyround1_simplfied) { retval = 2; // no match } } else if (*lhs == Ctrl_C) { @@ -3373,7 +3374,7 @@ int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, buf_T mp->m_nowait = args->nowait; mp->m_silent = args->silent; mp->m_mode = mode; - mp->m_simplified = did_simplify && keyround == 1; + mp->m_simplified = keyround1_simplfied; // Notice this when porting patch 8.2.0807 mp->m_expr = args->expr; mp->m_script_ctx = current_sctx; mp->m_script_ctx.sc_lnum += sourcing_lnum; -- cgit