]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid some syscalls in locate-dominating-file
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 16 Jul 2025 15:43:14 +0000 (08:43 -0700)
committerEshel Yaron <me@eshelyaron.com>
Thu, 24 Jul 2025 11:53:13 +0000 (13:53 +0200)
* lisp/files.el (locate-dominating-file): Do not call
file-directory-p each time through a loop ascending the directory
hierarchy, as the file must be a directory after the first loop
iteration.  Instead, call file-directory-p just once, before the
loop starts, and do this only if the file name is not already that
of a directory.

(cherry picked from commit 2074951c2adff43be49822c344d6cf3fee2e29a5)

lisp/files.el

index 3885637ed5896ddb12764673785b2da277b72bcb..ab3126a55bc435972e10f39cf5950a0187e973db 100644 (file)
@@ -1128,14 +1128,15 @@ the function needs to examine, starting with FILE."
   ;; Represent /home/luser/foo as ~/foo so that we don't try to look for
   ;; `name' in /home or in /.
   (setq file (abbreviate-file-name (expand-file-name file)))
+  (when (and (not (directory-name-p file))
+            (file-directory-p file))
+    (setq file (file-name-as-directory file)))
   (let ((root nil)
         try)
     (while (not (or root
                     (null file)
                     (string-match locate-dominating-stop-dir-regexp file)))
-      (setq file (if (file-directory-p file)
-                     file
-                   (file-name-directory file))
+      (setq file (file-name-directory file)
             try (if (stringp name)
                     (file-exists-p (expand-file-name name file))
                   (funcall name file)))