Source-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src/distrib/utils/sysinst



On Fri, Jul 18, 2003 at 10:21:31AM -0400, Perry E. Metzger wrote:
> 
> David Laight <dsl%netbsd.org@localhost> 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@localhost



Home | Main Index | Thread Index | Old Index