From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18670 invoked from network); 9 Oct 1998 17:21:54 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 9 Oct 1998 17:21:54 -0000 Received: (from list@localhost) by math.gatech.edu (8.9.1/8.9.1) id NAA18811; Fri, 9 Oct 1998 13:15:00 -0400 (EDT) Resent-Date: Fri, 9 Oct 1998 13:15:00 -0400 (EDT) From: "Bart Schaefer" Message-Id: <981009101601.ZM25272@candle.brasslantern.com> Date: Fri, 9 Oct 1998 10:16:01 -0700 In-Reply-To: <9810031530.AA20041@ibmth.df.unipi.it> Comments: In reply to Peter Stephenson "PATCH: 3.1.4: autocd to directory in $PATH" (Oct 3, 5:30pm) References: <9810031530.AA20041@ibmth.df.unipi.it> X-Mailer: Z-Mail (4.0b.820 20aug96) To: Peter Stephenson , zsh-workers@math.gatech.edu (Zsh hackers list) Subject: Re: PATCH: 3.1.4: autocd to directory in $PATH MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Resent-Message-ID: <"o1-Ws2.0.sb4.KIa7s"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/4423 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu On Oct 3, 5:30pm, Peter Stephenson wrote: } Subject: PATCH: 3.1.4: autocd to directory in $PATH } } at the moment it looks to me like nothing other than the full } stat() horror would be a really worthwhile improvement on [...] } *************** } *** 1489,1494 **** } --- 1502,1509 ---- } char *cmdarg = (char *) peekfirst(args); } } hn = cmdnamtab->getnode(cmdnamtab, cmdarg); } + if (hn && !isreallycom((Cmdnam)hn)) } + hn = NULL; } if (!hn && isset(HASHCMDS) && strcmp(cmdarg, "..")) { } for (s = cmdarg; *s && *s != '/'; s++); } if (!*s) hn = (HashNode) hashcmd(cmdarg, pathchecked); (One more line of context added for clarity.) I haven't actually walked through this with a debugger, but it looks to me as though hn = NULL at that point is going to trigger the call to hashcmd(cmdarg, pathchecked), which in turn is going to call iscom() a second time; so you end up stat()ing the directory twice. Perhaps if (hn && !isreallycom((Cmdnam)hn)) hn = NULL; else if (!hn && isset(HASHCMDS) && strcmp(cmdarg, "..")) { ^^^^ would be better? Also, what about removing the improperly hashed directory from cmdnamtab once you've discovered that it isn't a command? That would (I think) get any real command with the same name put into the table the next time that name was used, so that you'll never needlessly stat() again. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com