unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* locate-dominating-file calls `stat' too eagerly
@ 2008-09-29 11:54 Eli Zaretskii
  2008-09-29 14:06 ` Stefan Monnier
  0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2008-09-29 11:54 UTC (permalink / raw)
  To: emacs-devel

This fragment from locate-dominating-file:

      (while (and dir
                  ;; As a heuristic, we stop looking up the hierarchy of
                  ;; directories as soon as we find a directory belonging to
                  ;; another user.  This should save us from looking in
                  ;; things like /net and /afs.  This assumes that all the
                  ;; files inside a project belong to the same user.
                  (let ((prev-user user))
                    (setq user (nth 2 (file-attributes dir)))
                    (or (null prev-user) (equal user prev-user))))
        (if (setq files (and (file-directory-p dir)
                             (directory-files dir 'full regexp)))
            (throw 'found (car files))
          (if (equal dir
                     (setq dir (file-name-directory
                                (directory-file-name dir))))
              (setq dir nil))))

repeatedly calls file-directory-p, even after file-directory-p already
returned non-nil, which means that thereafter anything that
file-name-directory returns will also necessarily be a directory.
That looks like inefficiency, doesn't it?  Here's the modification I
propose:

    (let ((user nil)
          ;; Abbreviate, so as to stop when we cross ~/.
          (dir (abbreviate-file-name (file-name-as-directory file)))
          files dir-seen)
      (while (and dir
                  ;; As a heuristic, we stop looking up the hierarchy of
                  ;; directories as soon as we find a directory belonging to
                  ;; another user.  This should save us from looking in
                  ;; things like /net and /afs.  This assumes that all the
                  ;; files inside a project belong to the same user.
                  (let ((prev-user user))
                    (setq user (nth 2 (file-attributes dir)))
                    (or (null prev-user) (equal user prev-user))))
        (if (setq files (and (or dir-seen 
				 (setq dir-seen (file-directory-p dir)))
                             (directory-files dir 'full regexp)))
            (throw 'found (car files))
          (if (equal dir
                     (setq dir (file-name-directory
                                (directory-file-name dir))))
              (setq dir nil))))

Does anyone see any problems with that, on any platform?




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-09-30 16:30 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-29 11:54 locate-dominating-file calls `stat' too eagerly Eli Zaretskii
2008-09-29 14:06 ` Stefan Monnier
2008-09-29 14:36   ` Eli Zaretskii
2008-09-29 16:19     ` Stefan Monnier
2008-09-29 19:05       ` Eli Zaretskii
2008-09-29 20:45         ` Stefan Monnier
2008-09-30  7:14           ` Eli Zaretskii
2008-09-30 14:02             ` Stefan Monnier
2008-09-30 16:30               ` Eli Zaretskii
2008-09-30 12:52   ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).