From owner-cvs-all Fri Apr 5 3:20:55 2002 Delivered-To: cvs-all@freebsd.org Received: from srv1.cosmo-project.de (srv1.cosmo-project.de [213.83.6.106]) by hub.freebsd.org (Postfix) with ESMTP id 4619537B41F; Fri, 5 Apr 2002 03:20:32 -0800 (PST) Received: (from uucp@localhost) by srv1.cosmo-project.de (8.11.6/8.11.6) with UUCP id g35BKJc27477; Fri, 5 Apr 2002 13:20:19 +0200 (CEST) (envelope-from ticso@cicely8.cicely.de) Received: from cicely8.cicely.de (cicely8.cicely.de [10.1.1.10]) by cicely5.cicely.de (8.12.1/8.12.1) with ESMTP id g35BAc6e044977; Fri, 5 Apr 2002 13:10:38 +0200 (CEST)?g (envelope-from ticso@cicely8.cicely.de) Received: from cicely8.cicely.de (localhost [127.0.0.1]) by cicely8.cicely.de (8.12.2/8.12.2) with ESMTP id g35BAcnU055040; Fri, 5 Apr 2002 13:10:38 +0200 (CEST) (envelope-from ticso@cicely8.cicely.de) Received: (from ticso@localhost) by cicely8.cicely.de (8.12.2/8.12.2/Submit) id g35BAXu6055039; Fri, 5 Apr 2002 13:10:33 +0200 (CEST) Date: Fri, 5 Apr 2002 13:10:33 +0200 From: Bernd Walter To: Mikhail Teterin Cc: obrien@FreeBSD.org, cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org Subject: Re: cvs commit: src/usr.bin/yacc main.c Message-ID: <20020405111032.GM51284@cicely8.cicely.de> References: <200204042215.g34MFDb67996@freefall.freebsd.org> <200204042243.g34MhonF007316@aldan.algebra.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200204042243.g34MhonF007316@aldan.algebra.com> User-Agent: Mutt/1.3.26i X-Operating-System: FreeBSD cicely8.cicely.de 5.0-CURRENT i386 Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Thu, Apr 04, 2002 at 05:43:50PM -0500, Mikhail Teterin wrote: > On 4 Apr, David E. O'Brien wrote: > > obrien 2002/04/04 14:15:13 PST > > > > Modified files: > > usr.bin/yacc main.c > > Log: > [...] > > Use strlen() rather than magic number. > [...] > > Beware of strlen :) The magic number was just a ``sizeof temp_form'' -- > computed at the code-writing time. Your change moved the computation to > run-time, which, IMHO, is too far. How about the following patch, which > will move it to the compile-time (untested): It's main - a *one time* code path. I'm all for adding performance, but rarely used code should favour for readability and size. Your suggestion is more complex and bigger. And finaly gcc with -O *knows* that strlen("some string") results in a constant value. > > Index: main.c > =================================================================== > RCS file: /home/ncvs/src/usr.bin/yacc/main.c,v > retrieving revision 1.19 > diff -U2 -r1.19 main.c > --- main.c 4 Apr 2002 22:15:56 -0000 1.19 > +++ main.c 4 Apr 2002 22:41:35 -0000 > @@ -302,9 +302,11 @@ > const char *tmpdir; > > - if (!(tmpdir = getenv("TMPDIR"))) > + if (!(tmpdir = getenv("TMPDIR"))) { > tmpdir = _PATH_TMP; > + len = sizeof _PATH_TMP - 1; > + } else > + len = strlen(tmpdir); > > - len = strlen(tmpdir); > - i = len + strlen(temp_form) + 1; > + i = len + sizeof temp_form; > if (len && tmpdir[len-1] != '/') > ++i; -- B.Walter COSMO-Project http://www.cosmo-project.de ticso@cicely.de Usergroup info@cosmo-project.de To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message