comparison src/list.c @ 19123:09f28c17ac58 v8.2.0121

patch 8.2.0121: filter() and map() on blob don't work Commit: https://github.com/vim/vim/commit/49c57ce50019b667e5005ce1cfb8cdc2e48bf868 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jan 15 20:51:34 2020 +0100 patch 8.2.0121: filter() and map() on blob don't work Problem: filter() and map() on blob don't work. Solution: Correct the code. (closes https://github.com/vim/vim/issues/5483)
author Bram Moolenaar <Bram@vim.org>
date Wed, 15 Jan 2020 21:00:04 +0100
parents f41b55f9357c
children 94eda51ba9ba
comparison
equal deleted inserted replaced
19122:271d016b8bf5 19123:09f28c17ac58
1687 } 1687 }
1688 else if (argvars[0].v_type == VAR_BLOB) 1688 else if (argvars[0].v_type == VAR_BLOB)
1689 { 1689 {
1690 int i; 1690 int i;
1691 typval_T tv; 1691 typval_T tv;
1692 varnumber_T val;
1692 1693
1693 // set_vim_var_nr() doesn't set the type 1694 // set_vim_var_nr() doesn't set the type
1694 set_vim_var_type(VV_KEY, VAR_NUMBER); 1695 set_vim_var_type(VV_KEY, VAR_NUMBER);
1695 1696
1696 for (i = 0; i < b->bv_ga.ga_len; i++) 1697 for (i = 0; i < b->bv_ga.ga_len; i++)
1697 { 1698 {
1698 tv.v_type = VAR_NUMBER; 1699 tv.v_type = VAR_NUMBER;
1699 tv.vval.v_number = blob_get(b, i); 1700 val = blob_get(b, i);
1701 tv.vval.v_number = val;
1700 set_vim_var_nr(VV_KEY, idx); 1702 set_vim_var_nr(VV_KEY, idx);
1701 if (filter_map_one(&tv, expr, map, &rem) == FAIL || did_emsg) 1703 if (filter_map_one(&tv, expr, map, &rem) == FAIL || did_emsg)
1702 break; 1704 break;
1703 if (tv.v_type != VAR_NUMBER) 1705 if (tv.v_type != VAR_NUMBER)
1704 { 1706 {
1705 emsg(_(e_invalblob)); 1707 emsg(_(e_invalblob));
1706 break; 1708 break;
1707 } 1709 }
1708 tv.v_type = VAR_NUMBER; 1710 if (map)
1709 blob_set(b, i, tv.vval.v_number); 1711 {
1710 if (!map && rem) 1712 if (tv.vval.v_number != val)
1713 blob_set(b, i, tv.vval.v_number);
1714 }
1715 else if (rem)
1711 { 1716 {
1712 char_u *p = (char_u *)argvars[0].vval.v_blob->bv_ga.ga_data; 1717 char_u *p = (char_u *)argvars[0].vval.v_blob->bv_ga.ga_data;
1713 1718
1714 mch_memmove(p + idx, p + i + 1, 1719 mch_memmove(p + i, p + i + 1,
1715 (size_t)b->bv_ga.ga_len - i - 1); 1720 (size_t)b->bv_ga.ga_len - i - 1);
1716 --b->bv_ga.ga_len; 1721 --b->bv_ga.ga_len;
1717 --i; 1722 --i;
1718 } 1723 }
1724 ++idx;
1719 } 1725 }
1720 } 1726 }
1721 else // argvars[0].v_type == VAR_LIST 1727 else // argvars[0].v_type == VAR_LIST
1722 { 1728 {
1723 // set_vim_var_nr() doesn't set the type 1729 // set_vim_var_nr() doesn't set the type