aboutsummaryrefslogtreecommitdiff
path: root/src/ex_cmds.c
diff options
context:
space:
mode:
authorMarco Hinz <mh.codebro@gmail.com>2014-04-14 14:13:56 +0200
committerThiago de Arruda <tpadilha84@gmail.com>2014-04-16 09:35:18 -0300
commit0e1e9148a3b8d33bf74ebee9e88f22f69f723072 (patch)
tree65ef4feb023b245d3de5849d9e63dac322808234 /src/ex_cmds.c
parentd322be894e532e9148979ab10f3e277f1f359eb1 (diff)
downloadrneovim-0e1e9148a3b8d33bf74ebee9e88f22f69f723072.tar.gz
rneovim-0e1e9148a3b8d33bf74ebee9e88f22f69f723072.tar.bz2
rneovim-0e1e9148a3b8d33bf74ebee9e88f22f69f723072.zip
vim-patch:7.4.232
Problem: ":%s/\n//" uses a lot of memory. (Aidan Marlin) Solution: Turn this into a join command. (Christian Brabandt) https://code.google.com/p/vim/source/detail?r=845608965bd9d0b2755997a7be812746885ff105
Diffstat (limited to 'src/ex_cmds.c')
-rw-r--r--src/ex_cmds.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index 02bb65f13e..e3d02357e1 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -3653,6 +3653,35 @@ void do_sub(exarg_T *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((const char *)pat, "\\n") == 0
+ && strlen((const char *)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;
+ }
+
+ do_join(eap->line2 - eap->line1 + 1, FALSE, TRUE, FALSE);
+ sub_nlines = sub_nsubs = eap->line2 - eap->line1 + 1;
+ do_sub_msg(FALSE);
+ ex_may_print(eap);
+
+ return;
+ }
+
/*
* Find trailing options. When '&' is used, keep old options.
*/