Skip to content

Commit c74fbfe

Browse files
committed
patch 8.2.0524: Win32: searching for file matches is slow
Problem: Win32: searching for file matches is slow. Solution: Instead of making another round to find any short filename, check for the short name right away. Avoid using an ordinary file like a directory. (Nir Lichtman, closes #5883)
1 parent 00d253e commit c74fbfe

2 files changed

Lines changed: 17 additions & 18 deletions

File tree

src/filepath.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ get_short_pathname(char_u **fnamep, char_u **bufp, int *fnamelen)
6464
if (l != 0)
6565
{
6666
char_u *p = utf16_to_enc(newbuf, NULL);
67+
6768
if (p != NULL)
6869
{
6970
vim_free(*bufp);
@@ -3047,6 +3048,7 @@ dos_expandpath(
30473048
WCHAR *wn = NULL; // UCS-2 name, NULL when not used.
30483049
char_u *matchname;
30493050
int ok;
3051+
char_u *p_alt;
30503052

30513053
// Expanding "**" may take a long time, check for CTRL-C.
30523054
if (stardepth > 0)
@@ -3161,24 +3163,34 @@ dos_expandpath(
31613163
while (ok)
31623164
{
31633165
p = utf16_to_enc(wfb.cFileName, NULL); // p is allocated here
3166+
31643167
if (p == NULL)
31653168
break; // out of memory
31663169

3170+
if (*wfb.cAlternateFileName == NUL)
3171+
p_alt == NULL;
3172+
else
3173+
p_alt = utf16_to_enc(wfb.cAlternateFileName, NULL);
3174+
31673175
// Ignore entries starting with a dot, unless when asked for. Accept
31683176
// all entries found with "matchname".
31693177
if ((p[0] != '.' || starts_with_dot
31703178
|| ((flags & EW_DODOT)
31713179
&& p[1] != NUL && (p[1] != '.' || p[2] != NUL)))
31723180
&& (matchname == NULL
31733181
|| (regmatch.regprog != NULL
3174-
&& vim_regexec(&regmatch, p, (colnr_T)0))
3182+
&& (vim_regexec(&regmatch, p, (colnr_T)0)
3183+
|| (p_alt != NULL
3184+
&& vim_regexec(&regmatch, p_alt, (colnr_T)0)))
3185+
))
31753186
|| ((flags & EW_NOTWILD)
31763187
&& fnamencmp(path + (s - buf), p, e - s) == 0)))
31773188
{
31783189
STRCPY(s, p);
31793190
len = (int)STRLEN(buf);
31803191

3181-
if (starstar && stardepth < 100)
3192+
if (starstar && stardepth < 100
3193+
&& (wfb.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
31823194
{
31833195
// For "**" in the pattern first go deeper in the tree to
31843196
// find matches.
@@ -3207,24 +3219,9 @@ dos_expandpath(
32073219
}
32083220
}
32093221

3222+
vim_free(p_alt);
32103223
vim_free(p);
32113224
ok = FindNextFileW(hFind, &wfb);
3212-
3213-
// If no more matches and no match was used, try expanding the name
3214-
// itself. Finds the long name of a short filename.
3215-
if (!ok && matchname != NULL && gap->ga_len == start_len)
3216-
{
3217-
STRCPY(s, matchname);
3218-
FindClose(hFind);
3219-
vim_free(wn);
3220-
wn = enc_to_utf16(buf, NULL);
3221-
if (wn != NULL)
3222-
hFind = FindFirstFileW(wn, &wfb);
3223-
else
3224-
hFind = INVALID_HANDLE_VALUE;
3225-
ok = (hFind != INVALID_HANDLE_VALUE);
3226-
VIM_CLEAR(matchname);
3227-
}
32283225
}
32293226

32303227
FindClose(hFind);

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,8 @@ static char *(features[]) =
738738

739739
static int included_patches[] =
740740
{ /* Add new patch number below this line */
741+
/**/
742+
524,
741743
/**/
742744
523,
743745
/**/

0 commit comments

Comments
 (0)