]> git.eshelyaron.com Git - emacs.git/commitdiff
Make searching for files faster under Windows
authorNicolás Bértolo <nicolasbertolo@gmail.com>
Thu, 13 May 2021 11:30:29 +0000 (13:30 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Thu, 13 May 2021 11:30:29 +0000 (13:30 +0200)
* src/lread.c (openp): Use faccessat to check that a file exists
before opening it on Windows (bug#41646).  This speeds up
searching for files.

src/lread.c

index d2e6323cb149f4ec1d9cfeb31f8e94ea44348ecd..bca53a9a37aaeb31540ab633d8e08724c6506625 100644 (file)
@@ -1945,7 +1945,17 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes,
              }
            else
              {
-               fd = emacs_open (pfn, O_RDONLY, 0);
+                /*  In some systems (like Windows) finding out if a
+                    file exists is cheaper to do than actually opening
+                    it.  Only open the file when we are sure that it
+                    exists.  */
+#ifdef WINDOWSNT
+                if (faccessat (AT_FDCWD, pfn, R_OK, AT_EACCESS))
+                  fd = -1;
+                else
+#endif
+                  fd = emacs_open (pfn, O_RDONLY, 0);
+
                if (fd < 0)
                  {
                    if (! (errno == ENOENT || errno == ENOTDIR))