Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 5 Apr 2002 13:10:33 +0200
From:      Bernd Walter <ticso@cicely8.cicely.de>
To:        Mikhail Teterin <mi@aldan.algebra.com>
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>
In-Reply-To: <200204042243.g34MhonF007316@aldan.algebra.com>
References:  <200204042215.g34MFDb67996@freefall.freebsd.org> <200204042243.g34MhonF007316@aldan.algebra.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020405111032.GM51284>