Potential speedup in Windows FSNode::getChildren().

Worst case is it doesn't improve at all.
This commit is contained in:
Stephen Anthony 2024-09-18 20:42:24 -02:30
parent 03c5d7f1cf
commit cb77dc1a8f
1 changed files with 23 additions and 24 deletions

View File

@ -110,28 +110,7 @@ AbstractFSNodePtr FSNodeWINDOWS::getParent() const
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool FSNodeWINDOWS::getChildren(AbstractFSList& myList, ListMode mode) const
{
if (_isPseudoRoot)
{
// Drives enumeration
TCHAR drive_buffer[100];
GetLogicalDriveStrings(sizeof(drive_buffer) / sizeof(TCHAR), drive_buffer);
char drive_name[2] = { '\0', '\0' };
for (TCHAR *current_drive = drive_buffer; *current_drive;
current_drive += _tcslen(current_drive) + 1)
{
FSNodeWINDOWS entry;
drive_name[0] = current_drive[0];
entry._displayName = drive_name;
entry._isDirectory = true;
entry._isFile = false;
entry._isPseudoRoot = false;
entry._path = current_drive;
myList.emplace_back(make_unique<FSNodeWINDOWS>(entry));
}
}
else
if (!_isPseudoRoot) [[likely]]
{
// Files enumeration
WIN32_FIND_DATA desc{};
@ -166,11 +145,31 @@ bool FSNodeWINDOWS::getChildren(AbstractFSList& myList, ListMode mode) const
entry._size = desc.nFileSizeHigh * (static_cast<size_t>(MAXDWORD) + 1) + desc.nFileSizeLow;
myList.emplace_back(make_unique<FSNodeWINDOWS>(entry));
}
while (FindNextFile(handle, &desc));
} while (FindNextFile(handle, &desc));
FindClose(handle);
}
else
{
// Drives enumeration
TCHAR drive_buffer[100];
GetLogicalDriveStrings(sizeof(drive_buffer) / sizeof(TCHAR), drive_buffer);
char drive_name[2] = { '\0', '\0' };
for (TCHAR *current_drive = drive_buffer; *current_drive;
current_drive += _tcslen(current_drive) + 1)
{
FSNodeWINDOWS entry;
drive_name[0] = current_drive[0];
entry._displayName = drive_name;
entry._isDirectory = true;
entry._isFile = false;
entry._isPseudoRoot = false;
entry._path = current_drive;
myList.emplace_back(make_unique<FSNodeWINDOWS>(entry));
}
}
return true;
}