Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] Use access instead of stat in hashdir
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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author