Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 5 Apr 2002 12:20:07 -0500 (EST)
From:      Mikhail Teterin <mi@aldan.algebra.com>
To:        ticso@cicely8.cicely.de
Cc:        obrien@FreeBSD.org, cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org
Subject:   Re: cvs commit: src/usr.bin/yacc main.c
Message-ID:  <200204051720.g35HK7nF011066@aldan.algebra.com>
In-Reply-To: <20020405111032.GM51284@cicely8.cicely.de>

next in thread | previous in thread | raw e-mail | index | archive | help
On  5 Apr, Bernd Walter wrote:
 
> It's main - a *one time* code path. I'm all for adding performance,
> but rarely used code should favour for readability and size.

Readability, actually, suffers -- one is left wondering: "Why is
strlen() used? Can its argument change -- what am I missing?" and spends
more time reading it, not less.

> Your suggestion is more complex and bigger.

I think, the increase in size or complexity is negligeble... The second
hunk (temp_form) makes the code actually smaller and simpler. The binary
will be smaller, though -- also negligebly.

> And finaly gcc with -O *knows* that strlen("some string") results in a
> constant value.

Only for const arguments. Which is not the case here -- the contents of
temp_form is modified, and only the programmer knows (the compiler does
not), that the mkstemp is going to leave the size intact.

I plan to stop participating in this thread. The thing works one way or
the other -- all I wanted was to call attention to a trend I'd rather I
not see, but hey...

	-mi
 
>> 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;



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?200204051720.g35HK7nF011066>