Forum > LazUtils
FindAllDirectories is slow
JuhaManninen:
Hi
LazUtils, unit FileUtil has function FindAllDirectories.
It uses the same idea as FindAllFiles, using TFileSearcher internally. Now only it overrides the DoDirectoryFound method.
I realized it must be slow. TFileSearcher searches also all files which it useless if you only want directories.
I am not using the function so this is not "my itch" and I am not planning to fix it now. I have other itches to scratch.
If someone else wants to fix it, I will happily apply the patch. It is a simple and confined task, not many dependencies like in the IDE's code. It can be very rewarding (if you like to optimize code) as the speedup will be significant.
Ideas can be taken from my r39299 in Lazarus trunk in which I implemented a thread to scan and search for FPC sources, or then just by improvising.
Juha
Bart:
Make DoSearch a protected function and override that?
Then you use faDirectory instead of faAnyfile for search attribute.
Bart
JuhaManninen:
--- Quote from: Bart on November 18, 2012, 05:52:54 pm ---Make DoSearch a protected function and override that?
Then you use faDirectory instead of faAnyfile for search attribute.
--- End quote ---
Yes, faDirectory must be used for sure. The rest of the implementation is a matter of taste. It could use an overridden DoSearch or just a simple custom code without classes.
Juha
Bart:
I'll give it a try when I have time.
I'll post it in Mantis when I'm ready (no commit rights).
Bart
Bart:
Observations:
1.
Using faDirectory as Attribute instead of faAnyfile, at least on Windows, won't speed up things.
It still lists all files too.
2.
I noticed TMaskList is used.
This is case-insensitive.
So on Linux 'abc*' will also return ABC.txt, which is rather un-linux like, but then again may be usefull when searching somethig like '*.jpg'
It would IMO be a good idea to extend TMask and TMaskList to have a case-sensitive option.
--- Code: --- TMask = class
private
FMask: TMaskString;
public
constructor Create(const AValue: String; const CaseSensitive: Boolean = False);
destructor Destroy; override;
function Matches(const AFileName: String): Boolean;
end;
--- End code ---
In my own version of my filesearcher I already implemented such.
Bart
Navigation
[0] Message Index
[#] Next page