patch 9.2.0151: blob_from_string() is slow for long strings

Commit: 
https://github.com/vim/vim/commit/475d6e2f1d72cd8520ab2d2b317ae2ff20777303
Author: Yasuhiro Matsumoto <[email protected]>
Date:   Fri Mar 13 17:36:34 2026 +0000

    patch 9.2.0151: blob_from_string() is slow for long strings
    
    Problem:  blob_from_string() is slow for long strings
    Solution: Use ga_grow() to allocate memory once, perform a bulk copy
              with mch_memmove() then translate NL to NUL in-place
              (Yasuhiro Matsumoto).
    
    closes: #19665
    
    Signed-off-by: Yasuhiro Matsumoto <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/strings.c b/src/strings.c
index fb14e7de6..c5e07590c 100644
--- a/src/strings.c
+++ b/src/strings.c
@@ -1232,13 +1232,20 @@ convert_string(string_T *str, char_u *from, char_u *to, 
string_T *ret)
     static void
 blob_from_string(char_u *str, blob_T *blob)
 {
-    char_u  *p;
+    int            len = (int)STRLEN(str);
+    char_u  *dest;
 
-    for (p = str; *p != NUL; ++p)
-    {
-       // Translate newlines in the string to NUL character
-       ga_append(&blob->bv_ga, (*p == NL) ? NUL : (int)*p);
-    }
+    if (len == 0)
+       return;
+    if (ga_grow(&blob->bv_ga, len) == FAIL)
+       return;
+    dest = (char_u *)blob->bv_ga.ga_data + blob->bv_ga.ga_len;
+    mch_memmove(dest, str, (size_t)len);
+    // Translate newlines in the string to NUL characters
+    for (int i = 0; i < len; ++i)
+       if (dest[i] == NL)
+           dest[i] = NUL;
+    blob->bv_ga.ga_len += len;
 }
 
 /*
diff --git a/src/version.c b/src/version.c
index 37ef83b97..9969dc786 100644
--- a/src/version.c
+++ b/src/version.c
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    151,
 /**/
     150,
 /**/

-- 
-- 
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 [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1w16ZM-003iB0-1g%40256bit.org.

Raspunde prin e-mail lui