Patch 7.4.1841
Problem:    The code to reallocate the buffer used for quickfix is repeated.
Solution:   Move the code to a function. (Yegappan Lakshmanan, closes #831)
Files:      src/quickfix.c, src/testdir/test_quickfix.vim


*** ../vim-7.4.1840/src/quickfix.c      2016-05-08 12:51:57.436135992 +0200
--- src/quickfix.c      2016-05-24 19:59:42.151085408 +0200
***************
*** 179,184 ****
--- 179,209 ----
   */
  #define LINE_MAXLEN 4096
  
+     static char_u *
+ qf_grow_linebuf(char_u **growbuf, int *growbufsiz, int newsz, int *allocsz)
+ {
+     /*
+      * If the line exceeds LINE_MAXLEN exclude the last
+      * byte since it's not a NL character.
+      */
+     *allocsz = newsz > LINE_MAXLEN ? LINE_MAXLEN - 1 : newsz;
+     if (*growbuf == NULL)
+     {
+       *growbuf = alloc(*allocsz + 1);
+       if (*growbuf == NULL)
+           return NULL;
+       *growbufsiz = *allocsz;
+     }
+     else if (*allocsz > *growbufsiz)
+     {
+       *growbuf = vim_realloc(*growbuf, *allocsz + 1);
+       if (*growbuf == NULL)
+           return NULL;
+       *growbufsiz = *allocsz;
+     }
+     return *growbuf;
+ }
+ 
  /*
   * Read the errorfile "efile" into memory, line by line, building the error
   * list.
***************
*** 538,561 ****
  
                    if (len > IOSIZE - 2)
                    {
!                       /*
!                        * If the line exceeds LINE_MAXLEN exclude the last
!                        * byte since it's not a NL character.
!                        */
!                       linelen = len > LINE_MAXLEN ? LINE_MAXLEN - 1 : len;
!                       if (growbuf == NULL)
!                       {
!                           growbuf = alloc(linelen + 1);
!                           growbufsiz = linelen;
!                       }
!                       else if (linelen > growbufsiz)
!                       {
!                           growbuf = vim_realloc(growbuf, linelen + 1);
!                           if (growbuf == NULL)
!                               goto qf_init_end;
!                           growbufsiz = linelen;
!                       }
!                       linebuf = growbuf;
                    }
                    else
                    {
--- 563,572 ----
  
                    if (len > IOSIZE - 2)
                    {
!                       linebuf = qf_grow_linebuf(&growbuf, &growbufsiz, len,
!                                                                   &linelen);
!                       if (linebuf == NULL)
!                           goto qf_init_end;
                    }
                    else
                    {
***************
*** 584,605 ****
                    len = (int)STRLEN(p_li->li_tv.vval.v_string);
                    if (len > IOSIZE - 2)
                    {
!                       linelen = len;
!                       if (linelen > LINE_MAXLEN)
!                           linelen = LINE_MAXLEN - 1;
!                       if (growbuf == NULL)
!                       {
!                           growbuf = alloc(linelen + 1);
!                           growbufsiz = linelen;
!                       }
!                       else if (linelen > growbufsiz)
!                       {
!                           if ((growbuf = vim_realloc(growbuf,
!                                       linelen + 1)) == NULL)
!                               goto qf_init_end;
!                           growbufsiz = linelen;
!                       }
!                       linebuf = growbuf;
                    }
                    else
                    {
--- 595,604 ----
                    len = (int)STRLEN(p_li->li_tv.vval.v_string);
                    if (len > IOSIZE - 2)
                    {
!                       linebuf = qf_grow_linebuf(&growbuf, &growbufsiz, len,
!                                                                   &linelen);
!                       if (linebuf == NULL)
!                           goto qf_init_end;
                    }
                    else
                    {
***************
*** 621,640 ****
                linelen = (int)STRLEN(p_buf);
                if (linelen > IOSIZE - 2)
                {
!                   if (growbuf == NULL)
!                   {
!                       growbuf = alloc(linelen + 1);
!                       growbufsiz = linelen;
!                   }
!                   else if (linelen > growbufsiz)
!                   {
!                       if (linelen > LINE_MAXLEN)
!                           linelen = LINE_MAXLEN - 1;
!                       if ((growbuf = vim_realloc(growbuf, linelen + 1)) == 
NULL)
!                           goto qf_init_end;
!                       growbufsiz = linelen;
!                   }
!                   linebuf = growbuf;
                }
                else
                    linebuf = IObuff;
--- 620,629 ----
                linelen = (int)STRLEN(p_buf);
                if (linelen > IOSIZE - 2)
                {
!                   linebuf = qf_grow_linebuf(&growbuf, &growbufsiz, len,
!                                                                   &linelen);
!                   if (linebuf == NULL)
!                       goto qf_init_end;
                }
                else
                    linebuf = IObuff;
*** ../vim-7.4.1840/src/testdir/test_quickfix.vim       2016-04-30 
13:16:45.537142117 +0200
--- src/testdir/test_quickfix.vim       2016-05-24 19:53:19.347090674 +0200
***************
*** 700,713 ****
  
  " Tests for the setqflist() and setloclist() functions
  function SetXlistTests(cchar, bnum)
    if a:cchar == 'c'
      let Xsetlist = function('setqflist')
      let Xgetlist = function('getqflist')
-     let Xnext = 'cnext'
    else
      let Xsetlist = function('setloclist', [0])
      let Xgetlist = function('getloclist', [0])
-     let Xnext = 'lnext'
    endif
  
    call Xsetlist([{'bufnr': a:bnum, 'lnum': 1},
--- 700,713 ----
  
  " Tests for the setqflist() and setloclist() functions
  function SetXlistTests(cchar, bnum)
+   let Xwindow = a:cchar . 'window'
+   let Xnext = a:cchar . 'next'
    if a:cchar == 'c'
      let Xsetlist = function('setqflist')
      let Xgetlist = function('getqflist')
    else
      let Xsetlist = function('setloclist', [0])
      let Xgetlist = function('getloclist', [0])
    endif
  
    call Xsetlist([{'bufnr': a:bnum, 'lnum': 1},
***************
*** 723,728 ****
--- 723,737 ----
    exe Xnext
    call assert_equal(3, line('.'))
  
+   " Appending entries to the list should not change the cursor position
+   " in the quickfix window
+   exe Xwindow
+   1
+   call Xsetlist([{'bufnr': a:bnum, 'lnum': 4},
+             \  {'bufnr': a:bnum, 'lnum': 5}], 'a')
+   call assert_equal(1, line('.'))
+   close
+ 
    call Xsetlist([{'bufnr': a:bnum, 'lnum': 3},
              \  {'bufnr': a:bnum, 'lnum': 4},
              \  {'bufnr': a:bnum, 'lnum': 5}], 'r')
*** ../vim-7.4.1840/src/version.c       2016-05-24 19:37:25.051103801 +0200
--- src/version.c       2016-05-24 19:58:46.903086168 +0200
***************
*** 755,756 ****
--- 755,758 ----
  {   /* Add new patch number below this line */
+ /**/
+     1841,
  /**/

-- 
Contrary to popular belief, it's often your clothing that gets promoted, not
you.
                                (Scott Adams - The Dilbert principle)

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

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

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui