0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

updated for version 7.4.232

Problem:    ":%s/\n//" uses a lot of memory. (Aidan Marlin)
Solution:   Turn this into a join command. (Christian Brabandt)
This commit is contained in:
Bram Moolenaar
2014-04-01 17:49:44 +02:00
parent efa304d760
commit fd3fe98b78
4 changed files with 29 additions and 2 deletions

View File

@@ -4420,6 +4420,31 @@ do_sub(eap)
endcolumn = (curwin->w_curswant == MAXCOL);
}
/* Recognize ":%s/\n//" and turn it into a join command, which is much
* more efficient.
* TODO: find a generic solution to make line-joining operations more
* efficient, avoid allocating a string that grows in size.
*/
if (STRCMP(pat, "\\n") == 0 && STRLEN(pat) == 2
&& *sub == NUL
&& (*cmd == NUL || (cmd[1] == NUL && (*cmd == 'g' || *cmd == 'l'
|| *cmd == 'p' || *cmd == '#'))))
{
curwin->w_cursor.lnum = eap->line1;
if (*cmd == 'l')
eap->flags = EXFLAG_LIST;
else if (*cmd == '#')
eap->flags = EXFLAG_NR;
else if (*cmd == 'p')
eap->flags = EXFLAG_PRINT;
(void)do_join(eap->line2 - eap->line1 + 1, FALSE, TRUE, FALSE);
sub_nlines = sub_nsubs = eap->line2 - eap->line1 + 1;
(void)do_sub_msg(FALSE);
ex_may_print(eap);
return;
}
/*
* Find trailing options. When '&' is used, keep old options.
*/