Posted By: ManipUni | Nov 5th @ 4:52 AM
page 1 of 1
Comments: 7 | Views: 205
ManipUni
ManipUni
Proving QQ for 5 years!

This what what happens when you call: Directory.GetFiles(path)
Directory.GetFiles(path, "*")
Directory.GetFiles(path, "*", SearchOption.TopDirectoryOnly)
InternalGetFileDirectoryNames(path, path, "*", true, false, SearchOption.TopDirectoryOnly);

Which within its own right isn't horrible. But then InternalGetFileDirectoryNames() spends 50% of its processing time doing this: Path.CheckSearchPattern("*");

So I didn't request a search pattern and yet I'm spending 51% of the call checking one for validity. That is a poor design if you ask me. All they needed to do was add this:

if(searchPattern.Length != 1 || searchPattern[0] != '*')
    Path.CheckSearchPattern(searchPattern);

Actually, an internal method probably shouldn't check the pattern at all. That should be the responsibility of the public methods... if they take a search pattern at all. This method could obviously use a lot of performance tweaking. However, considering they return a fully hydrated collection instead of enumerator, any performance improvements are going to be lost in the noise any way Wink. Wonder what they did in the improved versions in .NET 4?

exoteric
exoteric
I : Next<I>

Actually, instead of all these patterns, just make it higher-order; if the filter function does nothing, then it's low-cost. But to keep the oldschool way, yes, it's not optimized - not like you should be in shock finding unoptimized code in .Net (or anywhere else). I think the filtering, since it's the most flexible version should be the last one called and should simply check for "*" or "" and have an efficient path for that.

Actually, instead of all these patterns, just make it higher-order; if the filter function does nothing, then it's low-cost.

 

It's not low-cost. The patterns have the advantage that they can be processed (at least some of them) by the kernel or a remote file server.

I was just saying that replacing the search pattern with a filter function it's not always low-cost...

page 1 of 1
Comments: 7 | Views: 205
Microsoft Communities