[BUG][FIX]FileDirectory>directoryExists: a bit silly

tim at sumeru.stanford.edu tim at sumeru.stanford.edu
Sun Aug 3 23:15:05 UTC 2003


Currently to see if a directory exists we do a crazy amount of work.. 

First we split the path name up and make theparent directory  - which we
send #exists to see if it exists. Then we enumerate all the entries in
the parent and filter out the files to leave the directories which we
then scan for one that matches the requisite name.

Spotted the logical nonsense yet?  Yup, note the #exists message; it
checks for the existence of a directory by using a fast prim. Why not
use the damned prim to check for the directory we actually want to check
for?
I did a trivial hack to try out the idea and it turns out to be 600
times faster on my machine! I doubt it will make such a difference on
all platforms but I bet it will help on all of them. 

The revised code is :-
++++++++++++++
directoryExists: filenameOrPath
	"Answer true if a directory of the given name exists. The given name
may be either a full path name or a local directory within this
directory."
	"FileDirectory default directoryExists: FileDirectory default pathName"

	| fName dir |
	FileDirectory activeDirectoryClass splitName: filenameOrPath to:
		[:filePath :name |
			fName _ name.
			filePath isEmpty
				ifTrue: [dir _ self]
				ifFalse: [dir _ FileDirectory on: filePath]].

	^self isCaseSensitive 
			ifTrue:[dir directoryNames includes: fName]
			ifFalse:[(dir directoryNamed: fName) exists].

+++++++
which is very simplitic but shows the effect. I _think_ that we can drop
the whole isCaseSensitive bit. As I see it, if the OS is case sensitive
you want the exact match in which case plain old (dir directoryNamed:
fName) exists should be correct and if the OS is case insensitive then
(dir directoryNamed: fName) exists will work as well. It seems ok on Mac
& Acorn.

I'm fairly sure that 
+++++++
directoryExists: filenameOrPath
	"Answer true if a directory of the given name exists. The given name
may be either a full path name or a local directory within this
directory."
	"FileDirectory default directoryExists: FileDirectory default pathName"

	^(FileDirectory default directoryNamed: filenameOrPath ) exists
++++++++++++++
would actually be correct

tim













< I'm a bug-fixing machine! >

This post brought to you by the BugFixArchiveViewer, a handy tool that
makes it easy to comment on proposed fixes and enhancements for Squeak. 
For more information, check out the Web page for the BugFixArchiveViewer
project: http://minnow.cc.gatech.edu/squeak/3214 

< I'm a bug-fixing machine! >



More information about the Squeak-dev mailing list