Hi all.

Joining lines by backslash in Vim scripts are bits slow.
Currently, it call alloc/strcpy/strcat/free in each lines.

let foo = "foooo"
\.        "foooo"
\.        "foooo"

It should use ga_init2/ga_concat.

Patch is here: https://gist.github.com/1598921

Below is a benchmark result.

--------------------------------
foo.log
=======

2000 operations of joining 4 lines. and 1 operation of joining 2000 lines.

https://raw.github.com/mattn/vimjp-issue-123/master/foo.vim

|original| patched|    %|
|--------|--------|-----|
|0.578287|0.284685| 49.2|
|0.575204|0.284810| 49.5|
|0.577512|0.284540| 49.2|

bar.log
=======

12000 operations of joining two lines.

https://raw.github.com/mattn/vimjp-issue-123/master/bar.vim

|original| patched|    %|
|--------|--------|-----|
|0.070951|0.071277|100.4|
|0.070916|0.071782|101.2|
|0.071404|0.071338| 99.9|

baz.log
=======

10000 operations of no joinings.

https://raw.github.com/mattn/vimjp-issue-123/master/baz.vim

|original| patched|    %|
|--------|--------|-----|
|0.045680|0.045479| 99.5|
|0.046300|0.045368| 97.9|
|0.045338|0.045529|100.4|

--------------------------------

diff -r 0dabc2ce136c src/ex_cmds2.c
--- a/src/ex_cmds2.c Tue Jan 10 22:31:32 2012 +0100
+++ b/src/ex_cmds2.c Thu Jan 12 14:09:52 2012 +0900
@@ -3439,22 +3439,30 @@
     {
  /* compensate for the one line read-ahead */
  --sourcing_lnum;
- for (;;)
+
+ p = NULL;
+ sp->nextline = get_one_sourceline(sp);
+ if (sp->nextline != NULL && *(p = skipwhite(sp->nextline)) == '\\')
  {
-    sp->nextline = get_one_sourceline(sp);
-    if (sp->nextline == NULL)
- break;
-    p = skipwhite(sp->nextline);
-    if (*p != '\\')
- break;
-    s = alloc((unsigned)(STRLEN(line) + STRLEN(p)));
-    if (s == NULL) /* out of memory */
- break;
-    STRCPY(s, line);
-    STRCAT(s, p + 1);
+    garray_T    ga;
+
+    ga_init2(&ga, (int)sizeof(char_u), 200);
+    ga_concat(&ga, line);
+    ga_concat(&ga, p + 1);
+    for (;;)
+    {
+ vim_free(sp->nextline);
+ sp->nextline = get_one_sourceline(sp);
+ if (sp->nextline == NULL)
+    break;
+ p = skipwhite(sp->nextline);
+ if (*p != '\\')
+    break;
+ ga_concat(&ga, p + 1);
+    }
+    ga_append(&ga, NUL);
     vim_free(line);
-    line = s;
-    vim_free(sp->nextline);
+    line = ga.ga_data;
  }
     }
 

-- 
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

Raspunde prin e-mail lui