]> granicus.if.org Git - vim/commitdiff
patch 8.1.2120: some MB_ macros are more complicated than necessary v8.1.2120
authorBram Moolenaar <Bram@vim.org>
Sun, 6 Oct 2019 20:00:13 +0000 (22:00 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 6 Oct 2019 20:00:13 +0000 (22:00 +0200)
Problem:    Some MB_ macros are more complicated than necessary. (Dominique
            Pelle)
Solution:   Simplify the macros.  Expand inline.

18 files changed:
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/macros.h
src/ops.c
src/os_mswin.c
src/popupmenu.c
src/search.c
src/spell.c
src/spellsuggest.c
src/terminal.c
src/version.c

index 69e667d63971e78cd4742a99ed527c0eac18f9bd..8ef8e8e1d5baa834d369597f0f2d725cdac10a62 100644 (file)
@@ -92,7 +92,7 @@ find_word_under_cursor(
                        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);
+                           len += mb_ptr2len(lbuf + epos->col);
                        lbuf = vim_strnsave(lbuf + spos->col, len);
                        lnum = spos->lnum;
                        col = spos->col;
index 01125aaf46cb48bfec829da213927e5755a086e5..ece7bf57d68421558dffdc9990129266829be3b1 100644 (file)
@@ -744,7 +744,7 @@ diff_write_buffer(buf_T *buf, diffin_T *din)
                // 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);
+               orig_len = mb_ptr2len(s);
                if (mb_char2bytes(c, cbuf) != orig_len)
                    // TODO: handle byte length difference
                    mch_memmove(ptr + len, s, orig_len);
index 954e07fb4a67b2ba5c4ec3ba62edd482beeede62..0fe8fd34aa9cc04fe8c028f8131b82f75b62b3ff 100644 (file)
@@ -6446,7 +6446,7 @@ do_string_sub(
                if (zero_width == regmatch.startp[0])
                {
                    /* avoid getting stuck on a match with an empty string */
-                   i = MB_PTR2LEN(tail);
+                   i = mb_ptr2len(tail);
                    mch_memmove((char_u *)ga.ga_data + ga.ga_len, tail,
                                                                   (size_t)i);
                    ga.ga_len += i;
index 26d8691ccfded2b4248eacc0b474f1ca671fa842..4a04696d6bcedf4286de9e8b24f0b3344ffccf12 100644 (file)
@@ -6454,7 +6454,7 @@ f_setcharsearch(typval_T *argvars, typval_T *rettv UNUSED)
            }
            else
                set_last_csearch(PTR2CHAR(csearch),
-                                               csearch, MB_PTR2LEN(csearch));
+                                               csearch, mb_ptr2len(csearch));
        }
 
        di = dict_find(d, (char_u *)"forward", -1);
index ef87413b7cf028697effcf3976ac15b7d7f3b7a1..838bd8404586f53a7785573245945538920610be 100644 (file)
@@ -2781,7 +2781,7 @@ redraw:
                    }
                    else
                    {
-                       len = MB_PTR2LEN(p);
+                       len = mb_ptr2len(p);
                        msg_outtrans_len(p, len);
                        vcol += ptr2cells(p);
                        p += len;
index 5ffb8c9b4ab3d4648ba3fe1d7c42330281f52558..3a06eec7b382601d4bcd1e57c659c27fdff2a089 100644 (file)
@@ -2613,9 +2613,9 @@ vim_fnamencmp(char_u *x, char_u *y, size_t len)
                && !(cx == '/' && cy == '\\')
                && !(cx == '\\' && cy == '/')))
            break;
-       len -= MB_PTR2LEN(px);
-       px += MB_PTR2LEN(px);
-       py += MB_PTR2LEN(py);
+       len -= mb_ptr2len(px);
+       px += mb_ptr2len(px);
+       py += mb_ptr2len(py);
     }
     if (len == 0)
        return 0;
@@ -3769,14 +3769,14 @@ pathcmp(const char *p, const char *q, int maxlen)
                    : c1 - c2;  // no match
        }
 
-       i += MB_PTR2LEN((char_u *)p + i);
-       j += MB_PTR2LEN((char_u *)q + j);
+       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));
+    c2 = PTR2CHAR((char_u *)s + i + mb_ptr2len((char_u *)s + i));
     // ignore a trailing slash, but not "//" or ":/"
     if (c2 == NUL
            && i > 0
index 414dc4e14a1a696e01255f8bc7cc41cfb653f287..ddb4d10d2c98cb997b3a527a2669205188cee135 100644 (file)
@@ -1337,8 +1337,8 @@ ff_wc_equal(char_u *s1, char_u *s2)
        prev2 = prev1;
        prev1 = c1;
 
-       i += MB_PTR2LEN(s1 + i);
-       j += MB_PTR2LEN(s2 + j);
+       i += mb_ptr2len(s1 + i);
+       j += mb_ptr2len(s2 + j);
     }
     return s1[i] == s2[j];
 }
index 5e098dfcf8b8d72c79510d3ad3335d2337f70f27..85ceddeb4cc99c69f1638fc4e12641ec9cd8c31c 100644 (file)
@@ -2254,7 +2254,7 @@ handle_mapping(
                    char_u *p2 = mb_unescape(&p1);
 
                    if (has_mbyte && p2 != NULL
-                                       && MB_BYTE2LEN(tb_c1) > MB_PTR2LEN(p2))
+                                       && MB_BYTE2LEN(tb_c1) > mb_ptr2len(p2))
                        mlen = 0;
                }
 
index 725affcbfc72e9a606185b7bf02100f51aa02164..0fdd93a2671f0ef9b7a119353316ecc75def7fc0 100644 (file)
@@ -4392,7 +4392,7 @@ update_search_hl(
                    && col >= shl->startcol
                    && col < shl->endcol)
            {
-               int next_col = col + MB_PTR2LEN(*line + col);
+               int next_col = col + mb_ptr2len(*line + col);
 
                if (shl->endcol < next_col)
                    shl->endcol = next_col;
index 5e047c873fea4628418cea0ffa8c82a51b0d6356..f670046b3da5835e2a35240973dd67b0055ff67f 100644 (file)
  * 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)
+#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) : has_mbyte ? (*mb_ptr2len)(p) : (*p == NUL ? 0 : 1)
+#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 */
index e82a66b13271bce2506eeba4bbe79ce07437b265..aa6858492ad647f724fa00a8f64fe68fcb2c571f 100644 (file)
--- a/src/ops.c
+++ b/src/ops.c
@@ -3223,7 +3223,7 @@ do_addsub(
            while (ptr[col] != NUL
                    && !vim_isdigit(ptr[col])
                    && !(doalp && ASCII_ISALPHA(ptr[col])))
-               col += MB_PTR2LEN(ptr + col);
+               col += mb_ptr2len(ptr + col);
 
            while (col > 0
                    && vim_isdigit(ptr[col - 1])
@@ -3242,7 +3242,7 @@ do_addsub(
                && !vim_isdigit(ptr[col])
                && !(doalp && ASCII_ISALPHA(ptr[col])))
        {
-           int mb_len = MB_PTR2LEN(ptr + col);
+           int mb_len = mb_ptr2len(ptr + col);
 
            col += mb_len;
            length -= mb_len;
index 5fb4809d25196bca8b70f60f20e57c673c9637ab..b5ef8fce89c73ca69ad61c677911244424a93556 100644 (file)
@@ -1654,7 +1654,7 @@ mch_print_text_out(char_u *p, int len)
     /* This is wrong when printing spaces for a TAB. */
     if (p[len] != NUL)
     {
-       wlen = MB_PTR2LEN(p + len);
+       wlen = mb_ptr2len(p + len);
        wp = enc_to_utf16(p + len, &wlen);
        if (wp != NULL)
        {
index 846dbc264d3f8cfffc7bba73d862aa48c445dbcc..b88c6531c16afe873ef3dfb3b8a23ee01b57728f 100644 (file)
@@ -1151,7 +1151,7 @@ split_message(char_u *mesg, pumitem_T **array)
                }
            }
            item->cells += ptr2cells(p);
-           p += MB_PTR2LEN(p);
+           p += mb_ptr2len(p);
        }
        item->bytelen = p - item->start;
        if (item->cells > max_cells)
@@ -1195,7 +1195,7 @@ split_message(char_u *mesg, pumitem_T **array)
            {
                cells = item->indent * 2;
                for (p = item->start + skip; p < item->start + item->bytelen;
-                                                           p += MB_PTR2LEN(p))
+                                                           p += mb_ptr2len(p))
                    if ((cells += ptr2cells(p)) > BALLOON_MIN_WIDTH)
                        break;
                thislen = p - (item->start + skip);
index 63171a92c0a214a14e38ee69442252909b652591..a0ca8df6221827ea387979c8ef437c30ed1c2b93 100644 (file)
@@ -2078,7 +2078,7 @@ findmatchlimit(
                    find_mps_values(&initc, &findc, &backwards, FALSE);
                    if (findc)
                        break;
-                   pos.col += MB_PTR2LEN(linep + pos.col);
+                   pos.col += mb_ptr2len(linep + pos.col);
                }
                if (!findc)
                {
@@ -2657,14 +2657,14 @@ showmatch(
        if (PTR2CHAR(p) == c && (curwin->w_p_rl ^ p_ri))
            break;
 #endif
-       p += MB_PTR2LEN(p) + 1;
+       p += mb_ptr2len(p) + 1;
        if (PTR2CHAR(p) == c
 #ifdef FEAT_RIGHTLEFT
                && !(curwin->w_p_rl ^ p_ri)
 #endif
           )
            break;
-       p += MB_PTR2LEN(p);
+       p += mb_ptr2len(p);
        if (*p == NUL)
            return;
     }
@@ -5633,7 +5633,7 @@ exit_matched:
                    && action == ACTION_EXPAND
                    && !(compl_cont_status & CONT_SOL)
                    && *startp != NUL
-                   && *(p = startp + MB_PTR2LEN(startp)) != NUL)
+                   && *(p = startp + mb_ptr2len(startp)) != NUL)
                goto search_line;
        }
        line_breakcheck();
index de478a3ed0664b39b23563a616b123137f828a7e..607bb392e52aa096149abfdb898eefd573d698ed 100644 (file)
@@ -2621,7 +2621,7 @@ spell_iswordp(
 
     if (has_mbyte)
     {
-       l = MB_PTR2LEN(p);
+       l = mb_ptr2len(p);
        s = p;
        if (l == 1)
        {
index 41f4a73b17b5c2d4518c248bcdbb1e0e3452d503..a5f8b92fae1364b0a0931c49c937a16f94af346e 100644 (file)
@@ -1782,7 +1782,7 @@ suggest_trie_walk(
                        {
                            int     l;
 
-                           l = MB_PTR2LEN(fword + sp->ts_fidx);
+                           l = mb_ptr2len(fword + sp->ts_fidx);
                            if (fword_ends)
                            {
                                // Copy the skipped character to preword.
@@ -1937,7 +1937,7 @@ suggest_trie_walk(
                                // Correct ts_fidx for the byte length of the
                                // character (we didn't check that before).
                                sp->ts_fidx = sp->ts_fcharstart
-                                           + MB_PTR2LEN(
+                                           + mb_ptr2len(
                                                    fword + sp->ts_fcharstart);
                                // For changing a composing character adjust
                                // the score from SCORE_SUBST to
@@ -2053,7 +2053,7 @@ suggest_trie_walk(
                if (has_mbyte)
                {
                    c = mb_ptr2char(fword + sp->ts_fidx);
-                   stack[depth].ts_fidx += MB_PTR2LEN(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,9 +2266,9 @@ suggest_trie_walk(
            p = fword + sp->ts_fidx;
            if (has_mbyte)
            {
-               n = MB_PTR2LEN(p);
+               n = mb_ptr2len(p);
                c = mb_ptr2char(p + n);
-               mch_memmove(p + MB_PTR2LEN(p + n), p, n);
+               mch_memmove(p + mb_ptr2len(p + n), p, n);
                mb_char2bytes(c, p);
            }
            else
@@ -2354,11 +2354,11 @@ suggest_trie_walk(
            p = fword + sp->ts_fidx;
            if (has_mbyte)
            {
-               n = MB_PTR2LEN(p);
+               n = mb_ptr2len(p);
                c2 = mb_ptr2char(p + n);
-               fl = MB_PTR2LEN(p + n);
+               fl = mb_ptr2len(p + n);
                c = mb_ptr2char(p + n + fl);
-               tl = MB_PTR2LEN(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,10 +2427,10 @@ suggest_trie_walk(
            p = fword + sp->ts_fidx;
            if (has_mbyte)
            {
-               n = MB_PTR2LEN(p);
-               n += MB_PTR2LEN(p + n);
+               n = mb_ptr2len(p);
+               n += mb_ptr2len(p + n);
                c = mb_ptr2char(p + n);
-               tl = MB_PTR2LEN(p + n);
+               tl = mb_ptr2len(p + n);
                mch_memmove(p + tl, p, n);
                mb_char2bytes(c, p);
            }
@@ -2489,9 +2489,9 @@ suggest_trie_walk(
            if (has_mbyte)
            {
                c = mb_ptr2char(p);
-               tl = MB_PTR2LEN(p);
-               n = MB_PTR2LEN(p + tl);
-               n += MB_PTR2LEN(p + tl + n);
+               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);
            }
index 52487a3cf31e268ef1bc0458458336b4bc647c27..42a80cd7dcb29542de6e19e5f92bd806e65b38f6 100644 (file)
@@ -5431,7 +5431,7 @@ f_term_scrape(typval_T *argvars, typval_T *rettv)
            attrs = cellattr->attrs;
            fg = cellattr->fg;
            bg = cellattr->bg;
-           len = MB_PTR2LEN(p);
+           len = mb_ptr2len(p);
            mch_memmove(mbs, p, len);
            mbs[len] = NUL;
            p += len;
index edbd0a717dc8b4c0560bb4f4d2878ccce530f57f..f668b9704e36388f036db26e2d2e1704298e4db4 100644 (file)
@@ -753,6 +753,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2120,
 /**/
     2119,
 /**/