Mercurial > vim
diff src/ex_cmds.c @ 5776:845608965bd9 v7.4.232
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)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Tue, 01 Apr 2014 17:49:44 +0200 |
parents | 50dbef5e774a |
children | 80421d934ebd |
line wrap: on
line diff
--- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -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. */