View Single Post
 
Old 09-01-2013, 07:17 PM
AtmaWeapon's Avatar
AtmaWeapon AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

In my opinion there's dang near never a reason to use the SQL-like syntax, and especially never a reason to mix it with the functional syntax, but I like the idea of trying to parallelize it.

Intuitively, I think it'd be more efficient to do the Where() first. GetFiles() has to enumerate the hard drive once no matter what. OrderBy() is going to have to sort and is likely O(n log(n)), but if you let the Where clause filter first, you'll end up with a smaller overall n.

Code:
Dim supportedExtensions As String = "*.zip,*.aaa,*.bbb,*.ccc,*.ddd"
Dim fileSelector = Function(filePath As String) As Boolean
                    Return supportedExtensions.Contains(Path.GetExtension(filePath))
                   End Function
Dim filteredFiles = Directory.GetFiles(fromPath, "*.*", SearchOption.AllDirectories) _
                        .AsParallel() _
                        .Where(fileSelector) _
                        .OrderBy(Function(x) x)
   
For Each fi As String In filteredFiles
    ...
Next
No clue if that's actually valid, C# is much more sane with respect to line breaks and SQL. I don't have VS at home to test it out. I like moving as much out of the For Each statement as I can, though.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote