From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: locate-dominating-file calls `stat' too eagerly Date: Mon, 29 Sep 2008 14:54:50 +0300 Message-ID: Reply-To: Eli Zaretskii NNTP-Posting-Host: lo.gmane.org X-Trace: ger.gmane.org 1222689382 22487 80.91.229.12 (29 Sep 2008 11:56:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 29 Sep 2008 11:56:22 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Sep 29 13:57:20 2008 connect(): Connection refused Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KkHNG-0006aQ-FJ for ged-emacs-devel@m.gmane.org; Mon, 29 Sep 2008 13:57:10 +0200 Original-Received: from localhost ([127.0.0.1]:32876 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KkHMD-0008PA-RS for ged-emacs-devel@m.gmane.org; Mon, 29 Sep 2008 07:56:05 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KkHL3-0007hk-CI for emacs-devel@gnu.org; Mon, 29 Sep 2008 07:54:53 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KkHL0-0007hO-Dl for emacs-devel@gnu.org; Mon, 29 Sep 2008 07:54:51 -0400 Original-Received: from [199.232.76.173] (port=36298 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KkHKz-0007hK-EU for emacs-devel@gnu.org; Mon, 29 Sep 2008 07:54:49 -0400 Original-Received: from mtaout2.012.net.il ([84.95.2.4]:32205) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KkHKz-0000YG-4G for emacs-devel@gnu.org; Mon, 29 Sep 2008 07:54:49 -0400 Original-Received: from HOME-C4E4A596F7 ([77.127.170.116]) by i_mtaout2.012.net.il (HyperSendmail v2004.12) with ESMTPA id <0K7Y00IONH557OZ0@i_mtaout2.012.net.il> for emacs-devel@gnu.org; Mon, 29 Sep 2008 14:55:54 +0300 (IDT) X-012-Sender: halo1@inter.net.il X-detected-operating-system: by monty-python.gnu.org: Solaris 9.1 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:104217 Archived-At: 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?