zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh workers <zsh-workers@zsh.org>
Subject: Re: [PATCH] Use access instead of stat in hashdir
Date: Mon, 06 Feb 2012 08:52:29 -0800	[thread overview]
Message-ID: <120206085229.ZM9099@torch.brasslantern.com> (raw)
In-Reply-To: <120206082008.ZM8593@torch.brasslantern.com>

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.


  reply	other threads:[~2012-02-06 16:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-06 13:13 Raghavendra D Prabhu
2012-02-06 16:20 ` Bart Schaefer
2012-02-06 16:52   ` Bart Schaefer [this message]
2012-02-07 22:46   ` Raghavendra D Prabhu
2012-02-08  0:40     ` Bart Schaefer

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=120206085229.ZM9099@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.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.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).