3ef2ca
To: vim_dev@googlegroups.com
3ef2ca
Subject: Patch 7.4.232
3ef2ca
Fcc: outbox
3ef2ca
From: Bram Moolenaar <Bram@moolenaar.net>
3ef2ca
Mime-Version: 1.0
3ef2ca
Content-Type: text/plain; charset=UTF-8
3ef2ca
Content-Transfer-Encoding: 8bit
3ef2ca
------------
3ef2ca
3ef2ca
Patch 7.4.232
3ef2ca
Problem:    ":%s/\n//" uses a lot of memory. (Aidan Marlin)
3ef2ca
Solution:   Turn this into a join command. (Christian Brabandt)
3ef2ca
Files:	    src/ex_cmds.c, src/ex_docmd.c, src/proto/ex_docmd.pro
3ef2ca
3ef2ca
3ef2ca
*** ../vim-7.4.231/src/ex_cmds.c	2014-03-23 15:12:29.919264336 +0100
3ef2ca
--- src/ex_cmds.c	2014-04-01 17:37:59.560901015 +0200
3ef2ca
***************
3ef2ca
*** 4420,4425 ****
3ef2ca
--- 4420,4450 ----
3ef2ca
  	endcolumn = (curwin->w_curswant == MAXCOL);
3ef2ca
      }
3ef2ca
  
3ef2ca
+     /* Recognize ":%s/\n//" and turn it into a join command, which is much
3ef2ca
+      * more efficient.
3ef2ca
+      * TODO: find a generic solution to make line-joining operations more
3ef2ca
+      * efficient, avoid allocating a string that grows in size.
3ef2ca
+      */
3ef2ca
+     if (STRCMP(pat, "\\n") == 0 && STRLEN(pat) == 2
3ef2ca
+ 	    && *sub == NUL
3ef2ca
+ 	    && (*cmd == NUL || (cmd[1] == NUL && (*cmd == 'g' || *cmd == 'l'
3ef2ca
+ 					     || *cmd == 'p' || *cmd == '#'))))
3ef2ca
+     {
3ef2ca
+ 	curwin->w_cursor.lnum = eap->line1;
3ef2ca
+ 	if (*cmd == 'l')
3ef2ca
+ 	    eap->flags = EXFLAG_LIST;
3ef2ca
+ 	else if (*cmd == '#')
3ef2ca
+ 	    eap->flags = EXFLAG_NR;
3ef2ca
+ 	else if (*cmd == 'p')
3ef2ca
+ 	    eap->flags = EXFLAG_PRINT;
3ef2ca
+ 
3ef2ca
+ 	(void)do_join(eap->line2 - eap->line1 + 1, FALSE, TRUE, FALSE);
3ef2ca
+ 	sub_nlines = sub_nsubs = eap->line2 - eap->line1 + 1;
3ef2ca
+ 	(void)do_sub_msg(FALSE);
3ef2ca
+ 	ex_may_print(eap);
3ef2ca
+ 	return;
3ef2ca
+     }
3ef2ca
+ 
3ef2ca
      /*
3ef2ca
       * Find trailing options.  When '&' is used, keep old options.
3ef2ca
       */
3ef2ca
*** ../vim-7.4.231/src/ex_docmd.c	2014-03-25 13:03:44.937793766 +0100
3ef2ca
--- src/ex_docmd.c	2014-04-01 17:31:59.708905965 +0200
3ef2ca
***************
3ef2ca
*** 316,322 ****
3ef2ca
  static void	ex_operators __ARGS((exarg_T *eap));
3ef2ca
  static void	ex_put __ARGS((exarg_T *eap));
3ef2ca
  static void	ex_copymove __ARGS((exarg_T *eap));
3ef2ca
- static void	ex_may_print __ARGS((exarg_T *eap));
3ef2ca
  static void	ex_submagic __ARGS((exarg_T *eap));
3ef2ca
  static void	ex_join __ARGS((exarg_T *eap));
3ef2ca
  static void	ex_at __ARGS((exarg_T *eap));
3ef2ca
--- 316,321 ----
3ef2ca
***************
3ef2ca
*** 8683,8689 ****
3ef2ca
  /*
3ef2ca
   * Print the current line if flags were given to the Ex command.
3ef2ca
   */
3ef2ca
!     static void
3ef2ca
  ex_may_print(eap)
3ef2ca
      exarg_T	*eap;
3ef2ca
  {
3ef2ca
--- 8682,8688 ----
3ef2ca
  /*
3ef2ca
   * Print the current line if flags were given to the Ex command.
3ef2ca
   */
3ef2ca
!     void
3ef2ca
  ex_may_print(eap)
3ef2ca
      exarg_T	*eap;
3ef2ca
  {
3ef2ca
*** ../vim-7.4.231/src/proto/ex_docmd.pro	2013-08-10 13:37:10.000000000 +0200
3ef2ca
--- src/proto/ex_docmd.pro	2014-04-01 17:31:59.708905965 +0200
3ef2ca
***************
3ef2ca
*** 54,57 ****
3ef2ca
--- 54,58 ----
3ef2ca
  int put_line __ARGS((FILE *fd, char *s));
3ef2ca
  void dialog_msg __ARGS((char_u *buff, char *format, char_u *fname));
3ef2ca
  char_u *get_behave_arg __ARGS((expand_T *xp, int idx));
3ef2ca
+ void ex_may_print __ARGS((exarg_T *eap));
3ef2ca
  /* vim: set ft=c : */
3ef2ca
*** ../vim-7.4.231/src/version.c	2014-04-01 14:08:14.689074130 +0200
3ef2ca
--- src/version.c	2014-04-01 17:33:03.920905082 +0200
3ef2ca
***************
3ef2ca
*** 736,737 ****
3ef2ca
--- 736,739 ----
3ef2ca
  {   /* Add new patch number below this line */
3ef2ca
+ /**/
3ef2ca
+     232,
3ef2ca
  /**/
3ef2ca
3ef2ca
-- 
3ef2ca
hundred-and-one symptoms of being an internet addict:
3ef2ca
16. You step out of your room and realize that your parents have moved and
3ef2ca
    you don't have a clue when it happened.
3ef2ca
3ef2ca
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
3ef2ca
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
3ef2ca
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
3ef2ca
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///