Subject: Re: Time taken for ls -la --color=yes
From: Fergus Henderson <[email-masked]>
To: "Larry Hall (RFK Partners, Inc)" <[email-masked]>
Cc: [email-masked], [email-masked]
Date: Tue, 9 Mar 1999 06:29:22 +1100

On 08-Mar-1999, Larry Hall (RFK Partners, Inc) <[email-masked]> wrote:
> At 01:26 PM 3/8/99 -0500, Henry J. Cobb wrote:
> >Doesn't LS take a lot of time to count the entries in every subdirectory it
> >encounters (even when it never lists them) just in order to fill out the
> >stat structures it then throws away?

Yes, I believe so.  Well, it's actually the stat() DLL call that
is taking the time, rather than the code in the `ls' executable itself.

There's no simple way for the stat() DLL call to figure out whether
the caller will use the `st_nlinks' field in the stat struct.
So it has to assume that it will be used.  And implementing Unix
semantics for the st_nlinks field when stat() is called on a directory
requires counting the number of subdirectories in that directory.

I suppose ls could be patched to use something other than stat().

The ideal solution would be to patch the compiler to automatically
figure out whether the caller was using the st_nlinks field, and
if not, to automatically substitute say `__cheap_stat()' instead of
`stat()'.  However, this is not very feasible in a language like C...

-- 
Fergus Henderson <[email-masked]>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger [email-masked]        |     -- the last words of T. S. Garp.

--
Want to unsubscribe from this list?
Send a message to [email-masked]