From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3596 invoked by alias); 6 Feb 2012 16:53:00 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 30184 Received: (qmail 26010 invoked from network); 6 Feb 2012 16:52:58 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <120206085229.ZM9099@torch.brasslantern.com> Date: Mon, 06 Feb 2012 08:52:29 -0800 In-reply-to: <120206082008.ZM8593@torch.brasslantern.com> Comments: In reply to Bart Schaefer "Re: [PATCH] Use access instead of stat in hashdir" (Feb 6, 8:20am) References: <20120206131302.GA46184@Xye> <120206082008.ZM8593@torch.brasslantern.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Zsh workers Subject: Re: [PATCH] Use access instead of stat in hashdir MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Feb 6, 8:20am, Bart Schaefer wrote: > > On Feb 6, 6:43pm, Raghavendra D Prabhu wrote: > } > } I found that using access instead of two stat calls results in > } faster rehash when it is done. I came across this when I noticed > } too many stat calls while 'strace -c' > > } if (unset(HASHEXECUTABLESONLY) || > } - (stat(pathbuf, &statbuf) == 0 && > } - S_ISREG(statbuf.st_mode) && (statbuf.st_mode & S_IXUGO))) > } + !access(pathbuf,X_OK)) > } add = 1; > } } In Src/exec.c the function iscom(): int iscom(char *s) { struct stat statbuf; char *us = unmeta(s); return (access(us, X_OK) == 0 && stat(us, &statbuf) >= 0 && S_ISREG(statbuf.st_mode)); } So let's see if we can get some speed out of this: Index: Src/hashtable.c =================================================================== diff -c -r1.20 Src/hashtable.c --- hashtable.c 1 Jun 2011 06:40:00 -0000 1.20 +++ hashtable.c 6 Feb 2012 16:49:24 -0000 @@ -663,8 +663,10 @@ * This is the same test as for the glob qualifier for * executable plain files. */ - if (stat(pathbuf, &statbuf) == 0 && - S_ISREG(statbuf.st_mode) && (statbuf.st_mode & S_IXUGO)) + if (unset(HASHEXECUTABLESONLY) || + (access(pathbuf, X_OK) == 0 && + stat(pathbuf, &statbuf) == 0 && + S_ISREG(statbuf.st_mode) && (statbuf.st_mode & S_IXUGO))) add = 1; } if (add) { The S_IXUGO test may now be redundant, but hardly worth skipping.