patch 9.1.0163: Calling STRLEN() to compute ml_line_textlen when not needed

Commit: 
https://github.com/vim/vim/commit/82e079df814f7372e9579450730062b205449efa
Author: zeertzjq <zeert...@outlook.com>
Date:   Sun Mar 10 08:55:42 2024 +0100

    patch 9.1.0163: Calling STRLEN() to compute ml_line_textlen when not needed
    
    Problem:  Calling STRLEN() to compute ml_line_textlen when not needed.
    Solution: Use 0 when STRLEN() will be required and call STRLEN() later.
              (zeertzjq)
    
    closes: #14155
    
    Signed-off-by: zeertzjq <zeert...@outlook.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/change.c b/src/change.c
index 847c18783..3af19b600 100644
--- a/src/change.c
+++ b/src/change.c
@@ -1364,7 +1364,7 @@ del_bytes(
            mch_memmove(newp + newlen + 1, oldp + oldlen + 1,
                               (size_t)curbuf->b_ml.ml_line_len - oldlen - 1);
        curbuf->b_ml.ml_line_len -= count;
-       curbuf->b_ml.ml_line_textlen = (int)STRLEN(newp) + 1;
+       curbuf->b_ml.ml_line_textlen = 0;
     }
 #endif
 
diff --git a/src/edit.c b/src/edit.c
index 998647cd8..26853dce0 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -5088,7 +5088,7 @@ ins_tab(void)
                        vim_free(curbuf->b_ml.ml_line_ptr);
                    curbuf->b_ml.ml_line_ptr = newp;
                    curbuf->b_ml.ml_line_len -= i;
-                   curbuf->b_ml.ml_line_textlen = (int)STRLEN(newp) + 1;
+                   curbuf->b_ml.ml_line_textlen = 0;
                    curbuf->b_ml.ml_flags =
                           (curbuf->b_ml.ml_flags | ML_LINE_DIRTY) & ~ML_EMPTY;
                }
diff --git a/src/memline.c b/src/memline.c
index 19d037f9e..99b9e9f2e 100644
--- a/src/memline.c
+++ b/src/memline.c
@@ -2700,9 +2700,13 @@ ml_get_cursor_len(void)
     colnr_T
 ml_get_buf_len(buf_T *buf, linenr_T lnum)
 {
-    if (*ml_get_buf(buf, lnum, FALSE) == NUL)
+    char_u     *line;
+
+    if (*(line = ml_get_buf(buf, lnum, FALSE)) == NUL)
         return 0;
 
+    if (buf->b_ml.ml_line_textlen <= 0)
+       buf->b_ml.ml_line_textlen = (int)STRLEN(line) + 1;
     return buf->b_ml.ml_line_textlen - 1;
 }
 
@@ -2799,8 +2803,11 @@ errorret:
        buf->b_ml.ml_line_ptr = (char_u *)dp + start;
        buf->b_ml.ml_line_len = end - start;
 #if defined(FEAT_BYTEOFF) && defined(FEAT_PROP_POPUP)
-       if (buf->b_has_textprop)
-           buf->b_ml.ml_line_textlen = (int)STRLEN(buf->b_ml.ml_line_ptr) + 1;
+       // Text properties come after a NUL byte, so ml_line_len should be
+       // larger than the size of textprop_T if there is any.
+       if (buf->b_has_textprop
+                        && (size_t)buf->b_ml.ml_line_len > sizeof(textprop_T))
+           buf->b_ml.ml_line_textlen = 0;  // call STRLEN() later when needed
        else
 #endif
            buf->b_ml.ml_line_textlen = buf->b_ml.ml_line_len;
diff --git a/src/structs.h b/src/structs.h
index b3b3f6a14..47a0050dd 100644
--- a/src/structs.h
+++ b/src/structs.h
@@ -802,8 +802,8 @@ typedef struct memline
 #define ML_ALLOCATED   0x10    // ml_line_ptr is an allocated copy
     int                ml_flags;
 
-    colnr_T    ml_line_len;    // length of the cached line + textproperties, 
including NUL
-    colnr_T    ml_line_textlen;// length of the cached line, including NUL
+    colnr_T    ml_line_len;    // length of the cached line + NUL + text 
properties
+    colnr_T    ml_line_textlen;// length of the cached line + NUL, 0 if not 
known yet
     linenr_T   ml_line_lnum;   // line number of cached line, 0 if not valid
     char_u     *ml_line_ptr;   // pointer to cached line
 
diff --git a/src/version.c b/src/version.c
index cc6335615..d1ca31bf6 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    163,
 /**/
     162,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1rjE6L-00AVdP-12%40256bit.org.

Raspunde prin e-mail lui