From: Eli Zaretskii <eliz@gnu.org>
To: emacs-devel@gnu.org
Subject: locate-dominating-file calls `stat' too eagerly
Date: Mon, 29 Sep 2008 14:54:50 +0300 [thread overview]
Message-ID: <u1vz3kvzp.fsf@gnu.org> (raw)
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?
next reply other threads:[~2008-09-29 11:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-29 11:54 Eli Zaretskii [this message]
2008-09-29 14:06 ` locate-dominating-file calls `stat' too eagerly 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=u1vz3kvzp.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).