On Wed, Mar 17, 2010 at 10:23 AM, Jens Alfke <j...@mooseyard.com> wrote:
>>  I'm pretty sure that just about any API that can retrieve a
>> filename from a directory will iterate through the whole directory
>> anyway.
>
> No; retrieving a file by name is just a B+tree lookup in HFS. Walking
> through the directory is a lot more expensive.

Ah, I didn't realize.  I know this is going to sound pretty stupid,
this being an OS X list and all, but I wasn't considering the HFS
filesystem.  I was thinking about some ancient UNIX filesystem I
studied a while back in which the filenames within a directory were
all concatenated together into an unsorted list.

At the time I actually considered inventing my own filesystem, because
I read of a study that found that fully half the time spent within the
UNIX kernel was spent within the namei() function, which converts a
single pathname element into an inode number.  My proposal was to use
a hash table for the filenames, so that a filename lookup would
consist mostly of a binary search of integers, rather than a linear
search of string comparisons.

I'm pretty sure that kind of thing is now done by most modern filesystems.

However I would argue that he might still be better off using readdir.
 The OP said he needed the case-preserved filenames of thousands of
files.  If a given directory tends to contain many of the files he
wants to identify, then readdir would efficiently get the filenames of
all those files all at once.

Your realpath method while undoubtably better for a single file might
actually be slower than readdir if one uses it for many files that are
all in a single directory.

Don Quixote
-- 
Don Quixote de la Mancha
quix...@dulcineatech.com
http://www.dulcineatech.com

   Dulcinea Technologies Corporation: Software of Elegance and Beauty.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to