Created attachment 596530 [details] [diff] [review] Patch v1. IsDirectory is called when enumerating directories unnecessarily. We can instead check it after the call to FindFirstFile which automatically returns the file attributes with it.
Most of the time when this function is called it is called on a directory, so in that case we basically do 2 calls to fetch file attributes.
(In reply to Brian R. Bondy from comment #0) > IsDirectory is called when enumerating directories unnecessarily. > We can instead check it after the call to FindFirstFile which automatically > returns the file attributes with it. But that returns the attributes of the found file, not the directory that we're enumerating. If people subsequently call IsDirectory on the found file, then yes, there is potential for optimisation there, but it would be nontrivial.
The first found file of a directory should be "." or the directory itself so this patch should work. Actually I think we can simplify this patch even more because OpenDir always adds \\* to the path so it would always return an error for a file. FindFirstFile returns ERROR_DIRECTORY if you pass <filepath>\* and it returns ERROR_PATH_NOT_FOUND when you have a <filepath_that_doesn't_exist>\*
Created attachment 596663 [details] [diff] [review] Patch v2.
Note: You can use FindFirstFileW on an actual file but not when you append \\* as we always do.
Comment on attachment 596663 [details] [diff] [review] Patch v2. Bah, I'm disappointed that bug 359808 didn't remove all the nsDir stuff from bug 162361 particularly given that they had the same author and reviewer!
Attachment #596663 - Flags: review?(neil) → review+
Status: NEW → RESOLVED
Last Resolved: 7 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.