On Mon, Aug 2, 2010 at 8:49 AM, Nazri Ramliy <ayieh...@gmail.com> wrote:
> On Thu, Jul 29, 2010 at 4:39 AM, Bram Moolenaar <b...@moolenaar.net> wrote:
>> I have included the recent patches, but not the one that resets
>> "recursive" in gen_expand_wildcards().  That is probably causing that
>> crash.
>
> I noticed that mch_expandpath() is defined on both unix and windows as
> unix_expandpath() and dos_expandpath(), respectively.  I'll see if it
> can be used in place of globpath() (which calls gen_expand_wildcards())
>  in the function expand_in_path().
>
> If that is successful I'll send a new patch for that and also revert 
> thechanges
> I did in globpath() (skipping url path).

It turned out that using unix_expandpath() for find completion is much,
much slower than using globpath.  I ended up using mch_expandpath only when
WIN3264 is defined, and use globpath() otherwise.

The benchmark result (doing a find completion for "jingle.gy" in the google
chrome source code, the fullname is "jingle.gyp"):

bench.vim:
---->8----
:set path=~/src/chrome/**
:find jingle.gy 
:q

----8<----
Note: there's a single tab character after jingle.gy

Result of running

  $ time ./vim-globpath -s bench.vim; time ./vim-mch_expandpath -s bench.vim

for five consecutive runs (whitespaces added to align the timing output below):

./vim-globpath       -s bench.vim  0.48s user 1.90s system 92% cpu 2.570 total
./vim-mch_expandpath -s bench.vim  4.26s user 3.97s system 90% cpu 9.135 total

./vim-globpath       -s bench.vim  0.53s user 1.64s system 93% cpu 2.310 total
./vim-mch_expandpath -s bench.vim  2.62s user 2.03s system 91% cpu 5.077 total

./vim-globpath       -s bench.vim  0.46s user 1.80s system 91% cpu 2.475 total
./vim-mch_expandpath -s bench.vim  3.39s user 3.10s system 86% cpu 7.471 total

./vim-globpath       -s bench.vim  0.44s user 1.47s system 88% cpu 2.153 total
./vim-mch_expandpath -s bench.vim  2.00s user 1.92s system 90% cpu 4.350 total

./vim-globpath       -s bench.vim  0.47s user 1.46s system 84% cpu 2.271 total
./vim-mch_expandpath -s bench.vim  2.59s user 2.41s system 96% cpu 5.185 total

Based on the benchmark result above it appears that using globpath() is about
4 times faster than using mch_expandpath() for doing find completion.

Attached patch makes find completion works on windows using mch_expandpath().
On unix we still use globpath().  This is done checking #if defined(WIN3264),
I'm not sure if that is the preferred way to detect if we're compiling on
windows.

> In the mean time here is the patch to prevent ":find <tab>" from crashing on
> windows when 'path" is set to something like "c:\src\**".

With the attached patch the above is no longer necessary.

For people who would like to test this out, please note the remark in :help
'path':

        - Careful with '\' characters, type two to get one in the option:
                :set path=.,c:\\include
          Or just use '/' instead: >
                :set path=.,c:/include

For example use ":set path=.,c:\\include\\**" or ":set path=.,c:/include/**"
to make vim recursively find completion candidates in c:\include directory.

nazri.

-- 
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
From 9540345bbf11461d7d8723306f1a9b2272e3661d Mon Sep 17 00:00:00 2001
From: nazri <ayieh...@gmail.com>
Date: Mon, 2 Aug 2010 16:10:56 +0800
Subject: [PATCH] Make find completion work on windows platform

---
 src/misc1.c |   78 +++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 68 insertions(+), 10 deletions(-)

diff --git a/src/misc1.c b/src/misc1.c
index 11c2b1b..8b96b68 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -9350,7 +9350,9 @@ expand_path_option(curdir, gap)
 	    STRMOVE(buf + curdir_len, buf + curdir_len + 1);
 	}
 
-	addfile(gap, buf, EW_NOTFOUND|EW_DIR|EW_FILE);
+	if (ga_grow(gap, 1) == FAIL)
+	    return;
+	((char_u **)gap->ga_data)[gap->ga_len++] = vim_strsave(buf);
     }
 
     vim_free(buf);
@@ -9378,8 +9380,11 @@ get_path_cutoff(fname, gap)
     {
 	int j = 0;
 
-	while (fname[j] == path_part[i][j] && fname[j] != NUL
-						   && path_part[i][j] != NUL)
+	while ((fname[j] == path_part[i][j]
+#if defined(WIN3264)
+		|| vim_ispathsep(fname[j]) && vim_ispathsep(path_part[i][j])
+#endif
+			     ) && fname[j] != NUL && path_part[i][j] != NUL)
 	    j++;
 	if (j > maxlen)
 	{
@@ -9389,8 +9394,15 @@ get_path_cutoff(fname, gap)
     }
 
     /* Skip to the file or directory name */
-    while (cutoff != NULL && vim_ispathsep(*cutoff) && *cutoff != NUL)
-	mb_ptr_adv(cutoff);
+    if (cutoff != NULL)
+	while (
+#if defined(WIN3264)
+		*cutoff == '/'
+#else
+		vim_ispathsep(*cutoff)
+#endif
+	      )
+	    mb_ptr_adv(cutoff);
 
     return cutoff;
 }
@@ -9454,7 +9466,13 @@ uniquefy_paths(gap, pattern)
 	char_u	    *dir_end = gettail(path);
 
 	len = (int)STRLEN(path);
-	while (dir_end > path && !vim_ispathsep(*dir_end))
+	while (dir_end > path &&
+#if defined(WIN3264)
+		*dir_end != '/'
+#else
+		!vim_ispathsep(*dir_end)
+#endif
+		)
 	    mb_ptr_back(path, dir_end);
 	is_in_curdir = STRNCMP(curdir, path, dir_end - path) == 0
 					     && curdir[dir_end - path] == NUL;
@@ -9536,6 +9554,47 @@ theend:
     }
 }
 
+#if defined(WIN3264)
+/*
+ * Calls mch_expandpath for each 'path' item concatenated with the given
+ * pattern and stores the result in gap.
+ * Returns the total number of matches.
+ */
+    static int
+expand_in_path(gap, pattern, flags)
+    garray_T	*gap;
+    char_u	*pattern;
+    int		flags;		/* EW_* flags */
+{
+    char_u	**path_list;
+    char_u	*curdir;
+    char_u	*file_pattern;
+    garray_T	path_ga;
+    int		i;
+
+    if ((curdir = alloc((int)(MAXPATHL))) == NULL)
+	return 0;
+    mch_dirname(curdir, MAXPATHL);
+
+    if ((file_pattern = alloc((int)(MAXPATHL))) == NULL)
+	return 0;
+
+    expand_path_option(curdir, &path_ga);
+    vim_free(curdir);
+    path_list = (char_u **)(path_ga.ga_data);
+    for (i = 0; i < path_ga.ga_len; i++)
+    {
+	if (STRLEN(path_list[i]) + STRLEN(pattern) + 2 > MAXPATHL)
+	    continue;
+	STRCPY(file_pattern, path_list[i]);
+	STRCAT(file_pattern, "/");
+	STRCAT(file_pattern, pattern);
+	mch_expandpath(gap, file_pattern, EW_DIR|EW_ADDSLASH|EW_FILE);
+    }
+
+    return gap->ga_len;
+}
+#else
 /*
  * Calls globpath with 'path' values for the given pattern and stores
  * the result in gap.
@@ -9547,7 +9606,6 @@ expand_in_path(gap, pattern, flags)
     char_u	*pattern;
     int		flags;		/* EW_* flags */
 {
-    int		c = 0;
     char_u	*files = NULL;
     char_u	*s;	/* start */
     char_u	*e;	/* end */
@@ -9609,12 +9667,12 @@ expand_in_path(gap, pattern, flags)
 	}
     }
 
-    c = gap->ga_len;
     vim_free(files);
 
-    return c;
+    return gap->ga_len;
 }
-#endif
+#endif /* WIN3264 */
+#endif /* FEAT_SEARCHPATH */
 
 #if defined(FEAT_SEARCHPATH) || defined(FEAT_CMDL_COMPL) || defined(PROTO)
 /*
-- 
1.7.2.1.6.g61bf12

Reply via email to