Subject: Re: bug#78306: [PATCH] Skip the non-exists path when loading a file on Windows

From: Eli Zaretskii <[email-masked]>
Date: Thu, 08 May 2025 11:46:22 +0300

> From: Michael Albinus <[email-masked]>
> Cc: Lin Sun <[email-masked]>,  [email-masked],  Stefan Monnier
>  <[email-masked]>
> Date: Thu, 08 May 2025 09:38:15 +0200
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> >   FOR_EACH_TAIL_SAFE (path)
> >    {
> >     ptrdiff_t baselen, prefixlen;
> >
> >     if (EQ (path, just_use_str))
> >       filename = str;
> >     else
> >       filename = Fexpand_file_name (str, XCAR (path));
> >     if (!complete_filename_p (filename))
> >       /* If there are non-absolute elts in PATH (eg ".").  */
> >       /* Of course, this could conceivably lose if luser sets
> > 	 default-directory to be something non-absolute...  */
> >       {
> > 	filename = Fexpand_file_name (filename, BVAR (current_buffer, directory));
> > 	if (!complete_filename_p (filename))
> > 	  /* Give up on this path element!  */
> > 	  continue;
> >       }
> >
> > we verify that 'XCAR (path)' (and possibly also the current buffer's
> > default-directory') is an accessible directory, e.g. by using
> > file-accessible-directory-p.  This might benefit Posix platforms as
> > well, but we should benchmark the results before we decide.  (We
> > should also consider how likely it is that load-path will include
> > non-directories or directories that don't exist.)
> >
> > Btw, did you benchmark the result of your proposed patch, and if so,
> > what is the speedup from this change?
> 
> I don't know whether the snippet above is also relevant for remote
> files. If yes, adding a call of file-accessible-directory-p might
> influence performance.

It could, yes.  In which case, depending on the speedups we measure in
local cases, we could only do this for local directories, or maybe
even only on MS-Windows.