Hi Bram,

>>
>>> >
>>> >> The attached patch makes the following changes to
>>> >> the quickfix tests:
>>> >>
>>> >> 1. Extends several test cases which currently tests only
>>> >>     quickfix list to also test location lists.
>>> >> 2. Uses command aliases for quickfix/location list commands,
>>> >>     instead of using "exe" to convert the command names.
>>> >
>>> > Thanks!
>>> >
>>> > I have been thinking of making :caddexpr work better by keeping state
>>> > between invocations.  What needs to be done (at least):
>>> >
>>> > - Move 'efm' parsing to a separate function.  If 'efm' is the same as last
>>> >   time re-use the fmt_first list.
>>> >
>>> > - Do not clear "dir_stack", "directory" and "file_stack", "currfile" when
>>> >   using ":caddexpr".
>>> >   Move multiline, multiignore, multiscan outside of the function.
>>> >
>>> > Perhaps more?
>>> >
>>> > We could perhaps use one of the existing tests for directory entry/exit
>>> > and instead of doing all lines at once feed one line at a time to
>>> > :caddexpr.
>>> >
>>>
>>> I am attaching a patch that implements all of the above changes.
>>> All the tests are passing. Need to review the diff and see whether
>>> any more changes are needed.
>>>
>>> BTW, I observed only a slight improvement in a simple caddexpr
>>> test with a large number of entries.
>>>
>>> Need to run additional tests to make sure this doesn't introduce
>>> any regressions.
>>
>> I haven't checked the whole patch, but I think that the cleanup of
>> dir_stack, multiline, etc. needs to be done when not adding to an
>> existing list.  Perhaps the tests always change 'errorformat' and they
>> get cleared for that reason.
>>
>
> To make it easier to include the changes, I am attaching a patch
> with only the refactoring changes. I have extracted the code that
> processes the 'errorformat' option into two functions. There are
> no functional changes in this patch. Once this goes in, we can add
> the optimization changes to process 'errorformat' only once (if
> it doesn't change between two invocations).
>

Now that the qf_init_ext() function refactoring changes are incorporated,
I am attaching a patch to optimize the qf_init_ext() function.
Now the errorformat option is processed only when a new errorformat
is used. Otherwise, the previously processed value is used.

- Yegappan

-- 
-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/quickfix.c b/src/quickfix.c
index b776025..2148386 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -532,25 +532,26 @@ qf_init_ext(
 #ifdef FEAT_WINDOWS
     qfline_T       *old_last = NULL;
 #endif
-    efm_T          *fmt_first = NULL;
+    static efm_T    *fmt_first = NULL;
     efm_T          *fmt_ptr;
     efm_T          *fmt_start = NULL;
     char_u         *efm;
+    static char_u   *last_efm = NULL;
     char_u         *ptr;
     int                    len;
     int                    i;
     int                    idx = 0;
-    int                    multiline = FALSE;
-    int                    multiignore = FALSE;
-    int                    multiscan = FALSE;
+    static int     multiline = FALSE;
+    static int     multiignore = FALSE;
+    static int     multiscan = FALSE;
     int                    retval = -1;        /* default: return error flag */
-    char_u         *directory = NULL;
-    char_u         *currfile = NULL;
+    static char_u   *directory = NULL;
+    static char_u   *currfile = NULL;
     char_u         *tail = NULL;
     char_u         *p_buf = NULL;
     char_u         *p_str = NULL;
     listitem_T     *p_li = NULL;
-    struct dir_stack_T  *file_stack = NULL;
+    static struct dir_stack_T  *file_stack = NULL;
     regmatch_T     regmatch;
 
     namebuf = alloc_id(CMDBUFFSIZE + 1, aid_qf_namebuf);
@@ -587,7 +588,30 @@ qf_init_ext(
     else
        efm = errorformat;
 
-    fmt_first = parse_efm_option(efm);
+    /*
+     * If the errorformat didn't change between calls, then reuse the
+     * previously parsed values.
+     */
+    if (last_efm == NULL || (STRCMP(last_efm, efm) != 0))
+    {
+       /* Free the previously parsed data */
+       vim_free(last_efm);
+       last_efm = NULL;
+       free_efm_list(&fmt_first);
+       qf_clean_dir_stack(&dir_stack);
+       qf_clean_dir_stack(&file_stack);
+
+       directory = NULL;
+       currfile = NULL;
+       multiline = FALSE;
+       multiignore = FALSE;
+       multiscan = FALSE;
+
+       fmt_first = parse_efm_option(efm);
+       if (fmt_first != NULL)
+           last_efm = vim_strsave(efm);
+    }
+
     if (fmt_first == NULL)     /* nothing found */
        goto error2;
 
@@ -1112,9 +1136,6 @@ error2:
 qf_init_end:
     if (fd != NULL)
        fclose(fd);
-    free_efm_list(&fmt_first);
-    qf_clean_dir_stack(&dir_stack);
-    qf_clean_dir_stack(&file_stack);
     vim_free(namebuf);
     vim_free(errmsg);
     vim_free(pattern);
diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim
index 1673ad6..88256bb 100644
--- a/src/testdir/test_quickfix.vim
+++ b/src/testdir/test_quickfix.vim
@@ -10,6 +10,7 @@ function! s:setup_commands(cchar)
   if a:cchar == 'c'
     command! -nargs=* -bang Xlist <mods>clist<bang> <args>
     command! -nargs=* Xgetexpr <mods>cgetexpr <args>
+    command! -nargs=* Xaddexpr <mods>caddexpr <args>
     command! -nargs=* Xolder <mods>colder <args>
     command! -nargs=* Xnewer <mods>cnewer <args>
     command! -nargs=* Xopen <mods>copen <args>
@@ -33,6 +34,7 @@ function! s:setup_commands(cchar)
   else
     command! -nargs=* -bang Xlist <mods>llist<bang> <args>
     command! -nargs=* Xgetexpr <mods>lgetexpr <args>
+    command! -nargs=* Xaddexpr <mods>laddexpr <args>
     command! -nargs=* Xolder <mods>lolder <args>
     command! -nargs=* Xnewer <mods>lnewer <args>
     command! -nargs=* Xopen <mods>lopen <args>
@@ -679,21 +681,25 @@ function! s:dir_stack_tests(cchar)
   let save_efm=&efm
   set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
 
-  let l = "Entering dir 'dir1/a'\n" .
-               \ 'habits2.txt:1:Nine Healthy Habits' . "\n" .
-               \ "Entering dir 'b'\n" .
-               \ 'habits3.txt:2:0 Hours of television' . "\n" .
-               \ 'habits2.txt:7:5 Small meals' . "\n" .
-               \ "Entering dir 'dir1/c'\n" .
-               \ 'habits4.txt:3:1 Hour of exercise' . "\n" .
-               \ "Leaving dir 'dir1/c'\n" .
-               \ "Leaving dir 'dir1/a'\n" .
-               \ 'habits1.txt:4:2 Liters of water' . "\n" .
-               \ "Entering dir 'dir2'\n" .
-               \ 'habits5.txt:5:3 Cups of hot green tea' . "\n"
-               \ "Leaving dir 'dir2'\n"
-
-  Xgetexpr l
+  let lines = ["Entering dir 'dir1/a'",
+               \ 'habits2.txt:1:Nine Healthy Habits',
+               \ "Entering dir 'b'",
+               \ 'habits3.txt:2:0 Hours of television',
+               \ 'habits2.txt:7:5 Small meals',
+               \ "Entering dir 'dir1/c'",
+               \ 'habits4.txt:3:1 Hour of exercise',
+               \ "Leaving dir 'dir1/c'",
+               \ "Leaving dir 'dir1/a'",
+               \ 'habits1.txt:4:2 Liters of water',
+               \ "Entering dir 'dir2'",
+               \ 'habits5.txt:5:3 Cups of hot green tea',
+               \ "Leaving dir 'dir2'"
+               \]
+
+  Xexpr ""
+  for l in lines
+      Xaddexpr l
+  endfor
 
   let qf = g:Xgetlist()
 
@@ -780,7 +786,10 @@ function! Test_efm2()
              \ "(67,3)  warning: 's' already defined"
              \]
   set efm=%+P[%f],(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%-Q
-  cgetexpr lines
+  cexpr ""
+  for l in lines
+      caddexpr l
+  endfor
   let l = getqflist()
   call assert_equal(9, len(l))
   call assert_equal(21, l[2].lnum)

Raspunde prin e-mail lui