Subject: Re: CVS commit: src/distrib/utils/sysinst
To: Perry E. Metzger <perry@piermont.com>
From: David Laight <david@l8s.co.uk>
List: source-changes
Date: 07/21/2003 22:56:04
On Fri, Jul 18, 2003 at 10:21:31AM -0400, Perry E. Metzger wrote:
>
> David Laight <dsl@netbsd.org> writes:
> > Change a lot of 'if (strlen(x) == 0)' to 'if (x[0] === 0)'.
>
> Why bother? Was this performance critical code? The former is clearer
> to the reader.
IMHO the latter is clearer, the test is 'is this string null' not
'does it have zero length'. I'll often write 'if (!*x)' to save keystrokes!
In any case, even on i386 gcc -O2 generates:
4: bf 00 00 00 00 mov $<string>,%edi
9: b0 00 mov $0x0,%al
b: fc cld
c: b9 ff ff ff ff mov $0xffffffff,%ecx
11: f2 ae repnz scas %es:(%edi),%al
13: 83 f9 fe cmp $0xfffffffe,%ecx
for the strlen() case.
This is sysinst, and size does matter.
David
--
David Laight: david@l8s.co.uk