To: vim_dev@googlegroups.com Subject: Patch 8.1.2120 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.2120 Problem: Some MB_ macros are more complicated than necessary. (Dominique Pelle) Solution: Simplify the macros. Expand inline. Files: src/macros.h, src/beval.c, src/diff.c src/eval.c src/evalfunc.c src/ex_getln.c, src/filepath.c, src/findfile.c, src/getchar.c, src/highlight.c, src/ops.c, src/os_mswin.c, src/popupmenu.c, src/search.c, src/spell.c, src/spellsuggest.c, src/terminal.c *** ../vim-8.1.2119/src/macros.h 2019-10-06 20:08:34.857333750 +0200 --- src/macros.h 2019-10-06 21:53:53.799655070 +0200 *************** *** 229,240 **** * MB_COPY_CHAR(f, t): copy one char from "f" to "t" and advance the pointers. * PTR2CHAR(): get character from pointer. */ - /* Get the length of the character p points to, including composing chars */ - #define MB_PTR2LEN(p) (has_mbyte ? (*mb_ptr2len)(p) : (*p == NUL ? 0 : 1)) /* Advance multi-byte pointer, skip over composing chars. */ ! #define MB_PTR_ADV(p) p += has_mbyte ? (*mb_ptr2len)(p) : (*p == NUL ? 0 : 1) /* Advance multi-byte pointer, do not skip over composing chars. */ ! #define MB_CPTR_ADV(p) p += enc_utf8 ? utf_ptr2len(p) : has_mbyte ? (*mb_ptr2len)(p) : (*p == NUL ? 0 : 1) /* Backup multi-byte pointer. Only use with "p" > "s" ! */ #define MB_PTR_BACK(s, p) p -= has_mbyte ? ((*mb_head_off)(s, p - 1) + 1) : 1 /* get length of multi-byte char, not including composing chars */ --- 229,238 ---- * MB_COPY_CHAR(f, t): copy one char from "f" to "t" and advance the pointers. * PTR2CHAR(): get character from pointer. */ /* Advance multi-byte pointer, skip over composing chars. */ ! #define MB_PTR_ADV(p) p += (*mb_ptr2len)(p) /* Advance multi-byte pointer, do not skip over composing chars. */ ! #define MB_CPTR_ADV(p) p += enc_utf8 ? utf_ptr2len(p) : (*mb_ptr2len)(p) /* Backup multi-byte pointer. Only use with "p" > "s" ! */ #define MB_PTR_BACK(s, p) p -= has_mbyte ? ((*mb_head_off)(s, p - 1) + 1) : 1 /* get length of multi-byte char, not including composing chars */ *** ../vim-8.1.2119/src/beval.c 2019-07-26 21:01:25.573903976 +0200 --- src/beval.c 2019-10-06 21:48:48.073717156 +0200 *************** *** 92,98 **** lbuf = ml_get_buf(curwin->w_buffer, VIsual.lnum, FALSE); len = epos->col - spos->col; if (*p_sel != 'e') ! len += MB_PTR2LEN(lbuf + epos->col); lbuf = vim_strnsave(lbuf + spos->col, len); lnum = spos->lnum; col = spos->col; --- 92,98 ---- lbuf = ml_get_buf(curwin->w_buffer, VIsual.lnum, FALSE); len = epos->col - spos->col; if (*p_sel != 'e') ! len += mb_ptr2len(lbuf + epos->col); lbuf = vim_strnsave(lbuf + spos->col, len); lnum = spos->lnum; col = spos->col; *** ../vim-8.1.2119/src/diff.c 2019-09-05 22:33:23.268963478 +0200 --- src/diff.c 2019-10-06 21:49:27.825442006 +0200 *************** *** 744,750 **** // xdiff doesn't support ignoring case, fold-case the text. c = PTR2CHAR(s); c = enc_utf8 ? utf_fold(c) : MB_TOLOWER(c); ! orig_len = MB_PTR2LEN(s); if (mb_char2bytes(c, cbuf) != orig_len) // TODO: handle byte length difference mch_memmove(ptr + len, s, orig_len); --- 744,750 ---- // xdiff doesn't support ignoring case, fold-case the text. c = PTR2CHAR(s); c = enc_utf8 ? utf_fold(c) : MB_TOLOWER(c); ! orig_len = mb_ptr2len(s); if (mb_char2bytes(c, cbuf) != orig_len) // TODO: handle byte length difference mch_memmove(ptr + len, s, orig_len); *** ../vim-8.1.2119/src/eval.c 2019-10-01 17:01:56.342282818 +0200 --- src/eval.c 2019-10-06 21:49:47.997303307 +0200 *************** *** 6446,6452 **** if (zero_width == regmatch.startp[0]) { /* avoid getting stuck on a match with an empty string */ ! i = MB_PTR2LEN(tail); mch_memmove((char_u *)ga.ga_data + ga.ga_len, tail, (size_t)i); ga.ga_len += i; --- 6446,6452 ---- if (zero_width == regmatch.startp[0]) { /* avoid getting stuck on a match with an empty string */ ! i = mb_ptr2len(tail); mch_memmove((char_u *)ga.ga_data + ga.ga_len, tail, (size_t)i); ga.ga_len += i; *** ../vim-8.1.2119/src/evalfunc.c 2019-10-01 17:01:56.346282798 +0200 --- src/evalfunc.c 2019-10-06 21:50:11.937139472 +0200 *************** *** 6454,6460 **** } else set_last_csearch(PTR2CHAR(csearch), ! csearch, MB_PTR2LEN(csearch)); } di = dict_find(d, (char_u *)"forward", -1); --- 6454,6460 ---- } else set_last_csearch(PTR2CHAR(csearch), ! csearch, mb_ptr2len(csearch)); } di = dict_find(d, (char_u *)"forward", -1); *** ../vim-8.1.2119/src/ex_getln.c 2019-10-01 17:38:46.480054071 +0200 --- src/ex_getln.c 2019-10-06 21:50:29.025023027 +0200 *************** *** 2781,2787 **** } else { ! len = MB_PTR2LEN(p); msg_outtrans_len(p, len); vcol += ptr2cells(p); p += len; --- 2781,2787 ---- } else { ! len = mb_ptr2len(p); msg_outtrans_len(p, len); vcol += ptr2cells(p); p += len; *** ../vim-8.1.2119/src/filepath.c 2019-09-10 21:27:15.171646995 +0200 --- src/filepath.c 2019-10-06 21:50:50.460877515 +0200 *************** *** 2613,2621 **** && !(cx == '/' && cy == '\\') && !(cx == '\\' && cy == '/'))) break; ! len -= MB_PTR2LEN(px); ! px += MB_PTR2LEN(px); ! py += MB_PTR2LEN(py); } if (len == 0) return 0; --- 2613,2621 ---- && !(cx == '/' && cy == '\\') && !(cx == '\\' && cy == '/'))) break; ! len -= mb_ptr2len(px); ! px += mb_ptr2len(px); ! py += mb_ptr2len(py); } if (len == 0) return 0; *************** *** 3769,3782 **** : c1 - c2; // no match } ! i += MB_PTR2LEN((char_u *)p + i); ! j += MB_PTR2LEN((char_u *)q + j); } if (s == NULL) // "i" or "j" ran into "maxlen" return 0; c1 = PTR2CHAR((char_u *)s + i); ! c2 = PTR2CHAR((char_u *)s + i + MB_PTR2LEN((char_u *)s + i)); // ignore a trailing slash, but not "//" or ":/" if (c2 == NUL && i > 0 --- 3769,3782 ---- : c1 - c2; // no match } ! i += mb_ptr2len((char_u *)p + i); ! j += mb_ptr2len((char_u *)q + j); } if (s == NULL) // "i" or "j" ran into "maxlen" return 0; c1 = PTR2CHAR((char_u *)s + i); ! c2 = PTR2CHAR((char_u *)s + i + mb_ptr2len((char_u *)s + i)); // ignore a trailing slash, but not "//" or ":/" if (c2 == NUL && i > 0 *** ../vim-8.1.2119/src/findfile.c 2019-09-04 15:54:23.916359692 +0200 --- src/findfile.c 2019-10-06 21:51:03.544788979 +0200 *************** *** 1337,1344 **** prev2 = prev1; prev1 = c1; ! i += MB_PTR2LEN(s1 + i); ! j += MB_PTR2LEN(s2 + j); } return s1[i] == s2[j]; } --- 1337,1344 ---- prev2 = prev1; prev1 = c1; ! i += mb_ptr2len(s1 + i); ! j += mb_ptr2len(s2 + j); } return s1[i] == s2[j]; } *** ../vim-8.1.2119/src/getchar.c 2019-10-03 22:35:46.688591474 +0200 --- src/getchar.c 2019-10-06 21:51:17.452695122 +0200 *************** *** 2254,2260 **** char_u *p2 = mb_unescape(&p1); if (has_mbyte && p2 != NULL ! && MB_BYTE2LEN(tb_c1) > MB_PTR2LEN(p2)) mlen = 0; } --- 2254,2260 ---- char_u *p2 = mb_unescape(&p1); if (has_mbyte && p2 != NULL ! && MB_BYTE2LEN(tb_c1) > mb_ptr2len(p2)) mlen = 0; } *** ../vim-8.1.2119/src/highlight.c 2019-09-14 21:00:01.383100879 +0200 --- src/highlight.c 2019-10-06 21:51:31.752598862 +0200 *************** *** 4392,4398 **** && col >= shl->startcol && col < shl->endcol) { ! int next_col = col + MB_PTR2LEN(*line + col); if (shl->endcol < next_col) shl->endcol = next_col; --- 4392,4398 ---- && col >= shl->startcol && col < shl->endcol) { ! int next_col = col + mb_ptr2len(*line + col); if (shl->endcol < next_col) shl->endcol = next_col; *** ../vim-8.1.2119/src/ops.c 2019-09-30 23:12:10.874289153 +0200 --- src/ops.c 2019-10-06 21:51:38.552553172 +0200 *************** *** 3223,3229 **** while (ptr[col] != NUL && !vim_isdigit(ptr[col]) && !(doalp && ASCII_ISALPHA(ptr[col]))) ! col += MB_PTR2LEN(ptr + col); while (col > 0 && vim_isdigit(ptr[col - 1]) --- 3223,3229 ---- while (ptr[col] != NUL && !vim_isdigit(ptr[col]) && !(doalp && ASCII_ISALPHA(ptr[col]))) ! col += mb_ptr2len(ptr + col); while (col > 0 && vim_isdigit(ptr[col - 1]) *************** *** 3242,3248 **** && !vim_isdigit(ptr[col]) && !(doalp && ASCII_ISALPHA(ptr[col]))) { ! int mb_len = MB_PTR2LEN(ptr + col); col += mb_len; length -= mb_len; --- 3242,3248 ---- && !vim_isdigit(ptr[col]) && !(doalp && ASCII_ISALPHA(ptr[col]))) { ! int mb_len = mb_ptr2len(ptr + col); col += mb_len; length -= mb_len; *** ../vim-8.1.2119/src/os_mswin.c 2019-09-21 23:09:00.975830710 +0200 --- src/os_mswin.c 2019-10-06 21:52:17.272294061 +0200 *************** *** 1654,1660 **** /* This is wrong when printing spaces for a TAB. */ if (p[len] != NUL) { ! wlen = MB_PTR2LEN(p + len); wp = enc_to_utf16(p + len, &wlen); if (wp != NULL) { --- 1654,1660 ---- /* This is wrong when printing spaces for a TAB. */ if (p[len] != NUL) { ! wlen = mb_ptr2len(p + len); wp = enc_to_utf16(p + len, &wlen); if (wp != NULL) { *** ../vim-8.1.2119/src/popupmenu.c 2019-09-27 13:07:59.569833456 +0200 --- src/popupmenu.c 2019-10-06 21:52:35.916169887 +0200 *************** *** 1151,1157 **** } } item->cells += ptr2cells(p); ! p += MB_PTR2LEN(p); } item->bytelen = p - item->start; if (item->cells > max_cells) --- 1151,1157 ---- } } item->cells += ptr2cells(p); ! p += mb_ptr2len(p); } item->bytelen = p - item->start; if (item->cells > max_cells) *************** *** 1195,1201 **** { cells = item->indent * 2; for (p = item->start + skip; p < item->start + item->bytelen; ! p += MB_PTR2LEN(p)) if ((cells += ptr2cells(p)) > BALLOON_MIN_WIDTH) break; thislen = p - (item->start + skip); --- 1195,1201 ---- { cells = item->indent * 2; for (p = item->start + skip; p < item->start + item->bytelen; ! p += mb_ptr2len(p)) if ((cells += ptr2cells(p)) > BALLOON_MIN_WIDTH) break; thislen = p - (item->start + skip); *** ../vim-8.1.2119/src/search.c 2019-09-28 19:04:06.997029566 +0200 --- src/search.c 2019-10-06 21:52:51.752064715 +0200 *************** *** 2078,2084 **** find_mps_values(&initc, &findc, &backwards, FALSE); if (findc) break; ! pos.col += MB_PTR2LEN(linep + pos.col); } if (!findc) { --- 2078,2084 ---- find_mps_values(&initc, &findc, &backwards, FALSE); if (findc) break; ! pos.col += mb_ptr2len(linep + pos.col); } if (!findc) { *************** *** 2657,2670 **** if (PTR2CHAR(p) == c && (curwin->w_p_rl ^ p_ri)) break; #endif ! p += MB_PTR2LEN(p) + 1; if (PTR2CHAR(p) == c #ifdef FEAT_RIGHTLEFT && !(curwin->w_p_rl ^ p_ri) #endif ) break; ! p += MB_PTR2LEN(p); if (*p == NUL) return; } --- 2657,2670 ---- if (PTR2CHAR(p) == c && (curwin->w_p_rl ^ p_ri)) break; #endif ! p += mb_ptr2len(p) + 1; if (PTR2CHAR(p) == c #ifdef FEAT_RIGHTLEFT && !(curwin->w_p_rl ^ p_ri) #endif ) break; ! p += mb_ptr2len(p); if (*p == NUL) return; } *************** *** 5633,5639 **** && action == ACTION_EXPAND && !(compl_cont_status & CONT_SOL) && *startp != NUL ! && *(p = startp + MB_PTR2LEN(startp)) != NUL) goto search_line; } line_breakcheck(); --- 5633,5639 ---- && action == ACTION_EXPAND && !(compl_cont_status & CONT_SOL) && *startp != NUL ! && *(p = startp + mb_ptr2len(startp)) != NUL) goto search_line; } line_breakcheck(); *** ../vim-8.1.2119/src/spell.c 2019-09-27 12:41:35.011573098 +0200 --- src/spell.c 2019-10-06 21:53:02.879990980 +0200 *************** *** 2621,2627 **** if (has_mbyte) { ! l = MB_PTR2LEN(p); s = p; if (l == 1) { --- 2621,2627 ---- if (has_mbyte) { ! l = mb_ptr2len(p); s = p; if (l == 1) { *** ../vim-8.1.2119/src/spellsuggest.c 2019-09-27 12:41:35.011573098 +0200 --- src/spellsuggest.c 2019-10-06 21:53:27.351829211 +0200 *************** *** 1782,1788 **** { int l; ! l = MB_PTR2LEN(fword + sp->ts_fidx); if (fword_ends) { // Copy the skipped character to preword. --- 1782,1788 ---- { int l; ! l = mb_ptr2len(fword + sp->ts_fidx); if (fword_ends) { // Copy the skipped character to preword. *************** *** 1937,1943 **** // Correct ts_fidx for the byte length of the // character (we didn't check that before). sp->ts_fidx = sp->ts_fcharstart ! + MB_PTR2LEN( fword + sp->ts_fcharstart); // For changing a composing character adjust // the score from SCORE_SUBST to --- 1937,1943 ---- // Correct ts_fidx for the byte length of the // character (we didn't check that before). sp->ts_fidx = sp->ts_fcharstart ! + mb_ptr2len( fword + sp->ts_fcharstart); // For changing a composing character adjust // the score from SCORE_SUBST to *************** *** 2053,2059 **** if (has_mbyte) { c = mb_ptr2char(fword + sp->ts_fidx); ! stack[depth].ts_fidx += MB_PTR2LEN(fword + sp->ts_fidx); if (enc_utf8 && utf_iscomposing(c)) stack[depth].ts_score -= SCORE_DEL - SCORE_DELCOMP; else if (c == mb_ptr2char(fword + stack[depth].ts_fidx)) --- 2053,2059 ---- if (has_mbyte) { c = mb_ptr2char(fword + sp->ts_fidx); ! stack[depth].ts_fidx += mb_ptr2len(fword + sp->ts_fidx); if (enc_utf8 && utf_iscomposing(c)) stack[depth].ts_score -= SCORE_DEL - SCORE_DELCOMP; else if (c == mb_ptr2char(fword + stack[depth].ts_fidx)) *************** *** 2266,2274 **** p = fword + sp->ts_fidx; if (has_mbyte) { ! n = MB_PTR2LEN(p); c = mb_ptr2char(p + n); ! mch_memmove(p + MB_PTR2LEN(p + n), p, n); mb_char2bytes(c, p); } else --- 2266,2274 ---- p = fword + sp->ts_fidx; if (has_mbyte) { ! n = mb_ptr2len(p); c = mb_ptr2char(p + n); ! mch_memmove(p + mb_ptr2len(p + n), p, n); mb_char2bytes(c, p); } else *************** *** 2354,2364 **** p = fword + sp->ts_fidx; if (has_mbyte) { ! n = MB_PTR2LEN(p); c2 = mb_ptr2char(p + n); ! fl = MB_PTR2LEN(p + n); c = mb_ptr2char(p + n + fl); ! tl = MB_PTR2LEN(p + n + fl); mch_memmove(p + fl + tl, p, n); mb_char2bytes(c, p); mb_char2bytes(c2, p + tl); --- 2354,2364 ---- p = fword + sp->ts_fidx; if (has_mbyte) { ! n = mb_ptr2len(p); c2 = mb_ptr2char(p + n); ! fl = mb_ptr2len(p + n); c = mb_ptr2char(p + n + fl); ! tl = mb_ptr2len(p + n + fl); mch_memmove(p + fl + tl, p, n); mb_char2bytes(c, p); mb_char2bytes(c2, p + tl); *************** *** 2427,2436 **** p = fword + sp->ts_fidx; if (has_mbyte) { ! n = MB_PTR2LEN(p); ! n += MB_PTR2LEN(p + n); c = mb_ptr2char(p + n); ! tl = MB_PTR2LEN(p + n); mch_memmove(p + tl, p, n); mb_char2bytes(c, p); } --- 2427,2436 ---- p = fword + sp->ts_fidx; if (has_mbyte) { ! n = mb_ptr2len(p); ! n += mb_ptr2len(p + n); c = mb_ptr2char(p + n); ! tl = mb_ptr2len(p + n); mch_memmove(p + tl, p, n); mb_char2bytes(c, p); } *************** *** 2489,2497 **** if (has_mbyte) { c = mb_ptr2char(p); ! tl = MB_PTR2LEN(p); ! n = MB_PTR2LEN(p + tl); ! n += MB_PTR2LEN(p + tl + n); mch_memmove(p, p + tl, n); mb_char2bytes(c, p + n); } --- 2489,2497 ---- if (has_mbyte) { c = mb_ptr2char(p); ! tl = mb_ptr2len(p); ! n = mb_ptr2len(p + tl); ! n += mb_ptr2len(p + tl + n); mch_memmove(p, p + tl, n); mb_char2bytes(c, p + n); } *** ../vim-8.1.2119/src/terminal.c 2019-10-01 17:01:56.346282798 +0200 --- src/terminal.c 2019-10-06 21:53:41.667734855 +0200 *************** *** 5431,5437 **** attrs = cellattr->attrs; fg = cellattr->fg; bg = cellattr->bg; ! len = MB_PTR2LEN(p); mch_memmove(mbs, p, len); mbs[len] = NUL; p += len; --- 5431,5437 ---- attrs = cellattr->attrs; fg = cellattr->fg; bg = cellattr->bg; ! len = mb_ptr2len(p); mch_memmove(mbs, p, len); mbs[len] = NUL; p += len; *** ../vim-8.1.2119/src/version.c 2019-10-06 20:08:34.857333750 +0200 --- src/version.c 2019-10-06 21:59:26.877506738 +0200 *************** *** 755,756 **** --- 755,758 ---- { /* Add new patch number below this line */ + /**/ + 2120, /**/ -- In Africa some of the native tribes have a custom of beating the ground with clubs and uttering spine chilling cries. Anthropologists call this a form of primitive self-expression. In America we call it golf. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///