From: "Bart Schaefer" <schaefer@brasslantern.com>
To: Peter Stephenson <pws@ibmth.df.unipi.it>,
zsh-workers@math.gatech.edu (Zsh hackers list)
Subject: PATCH: Re: PATCH: 3.1.4: autocd to directory in $PATH (2)
Date: Wed, 14 Oct 1998 12:07:22 -0700 [thread overview]
Message-ID: <981014120722.ZM19521@candle.brasslantern.com> (raw)
In-Reply-To: <9810121218.AA21544@ibmth.df.unipi.it>
On Oct 12, 2:18pm, Peter Stephenson wrote:
} Subject: PATCH: 3.1.4: autocd to directory in $PATH (2)
}
} The directory does get stat'ed twice, but it's hard to avoid without
} more fiddling around with special cases. The next fix does at least
} mean it's restricted to twice altogether.
It bothers me that this happens on every command execution.
Here's a patch, which must be applied on top of Peter's patch, that
restricts the two calls to stat to cases where an autocd might occur.
Specifically, this means:
* autocd is set
* the shell is reading commands from stdin
* there are no I/O redirections to perform
* there are no command arguments to pass
[I simply moved computation of these four conditions to the top of the
function, then tested the result both in the original context and also
before calling isreallycom().]
Thus there should be no performance penalty (compared to previous zsh
versions) for the great majority of commands, nor for any command if
you don't set autocd.
I did have two remarks about isreallycom():
} + isreallycom(Cmdnam cn)
} + {
} + char fullnam[MAXCMDLEN];
Other places in the code use PATH_MAX size buffer for the same purpose.
Which is better?
There also seems to be inconsistency as to:
} + strcpy(fullnam, cn->u.name ? *(cn->u.name) : "");
} + strcat(fullnam, "/");
} + strcat(fullnam, cn->nam);
as opposed to:
z = buf;
strucpy(&z, *pp);
*z++ = '/';
strcpy(z, arg0);
My patch doesn't change any of that stuff, I'm just pointing it out.
Index: Src/exec.c
===================================================================
*** exec.c 1998/10/14 18:19:05 1.4
--- exec.c 1998/10/14 18:22:09
***************
*** 1495,1500 ****
--- 1495,1504 ----
if (type == SIMPLE && !nullexec) {
char *s;
+ char trycd = (isset(AUTOCD) && isset(SHINSTDIN)
+ && empty(cmd->redir) && !empty(args)
+ && !nextnode(firstnode(args))
+ && *(char *)peekfirst(args));
DPUTS(empty(args), "BUG: empty(args) in exec.c");
if (!hn) {
***************
*** 1502,1508 ****
char *cmdarg = (char *) peekfirst(args);
hn = cmdnamtab->getnode(cmdnamtab, cmdarg);
! if (hn && !isreallycom((Cmdnam)hn)) {
cmdnamtab->removenode(cmdnamtab, cmdarg);
cmdnamtab->freenode(hn);
hn = NULL;
--- 1506,1512 ----
char *cmdarg = (char *) peekfirst(args);
hn = cmdnamtab->getnode(cmdnamtab, cmdarg);
! if (hn && trycd && !isreallycom((Cmdnam)hn)) {
cmdnamtab->removenode(cmdnamtab, cmdarg);
cmdnamtab->freenode(hn);
hn = NULL;
***************
*** 1516,1524 ****
/* If no command found yet, see if it *
* is a directory we should AUTOCD to. */
! if (!hn && isset(AUTOCD) && isset(SHINSTDIN) && empty(cmd->redir)
! && !nextnode(firstnode(args)) && *(char *)peekfirst(args)
! && (s = cancd(peekfirst(args)))) {
peekfirst(args) = (void *) s;
pushnode(args, dupstring("cd"));
if ((hn = builtintab->getnode(builtintab, "cd")))
--- 1520,1526 ----
/* If no command found yet, see if it *
* is a directory we should AUTOCD to. */
! if (!hn && trycd && (s = cancd(peekfirst(args)))) {
peekfirst(args) = (void *) s;
pushnode(args, dupstring("cd"));
if ((hn = builtintab->getnode(builtintab, "cd")))
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
prev parent reply other threads:[~1998-10-14 19:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-10-03 15:30 PATCH: 3.1.4: autocd to directory in $PATH Peter Stephenson
1998-10-09 17:16 ` Bart Schaefer
1998-10-12 12:18 ` PATCH: 3.1.4: autocd to directory in $PATH (2) Peter Stephenson
1998-10-14 19:07 ` Bart Schaefer [this message]
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=981014120722.ZM19521@candle.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=pws@ibmth.df.unipi.it \
--cc=zsh-workers@math.gatech.edu \
/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).