Further optimization to FSNodeWINDOWS; eliminate function call.

This commit is contained in:
Stephen Anthony 2023-01-26 16:44:16 -03:30
parent a4c5e57454
commit f72aff57a9
2 changed files with 27 additions and 46 deletions

View File

@ -141,10 +141,34 @@ bool FSNodeWINDOWS::getChildren(AbstractFSList& myList, ListMode mode) const
if (handle == INVALID_HANDLE_VALUE)
return false;
addFile(myList, mode, _path, desc);
do {
const char* const asciiName = desc.cFileName;
while (FindNextFile(handle, &desc))
addFile(myList, mode, _path, desc);
// Skip files starting with '.' (we assume empty filenames never occur)
if (asciiName[0] == '.')
continue;
const bool isDirectory = static_cast<bool>(desc.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
const bool isFile = !isDirectory;
if ((isFile && mode == FSNode::ListMode::DirectoriesOnly) ||
(isDirectory && mode == FSNode::ListMode::FilesOnly))
continue;
FSNodeWINDOWS entry;
entry._isDirectory = isDirectory;
entry._isFile = isFile;
entry._displayName = asciiName;
entry._path = _path;
entry._path += asciiName;
if (entry._isDirectory)
entry._path += FSNode::PATH_SEPARATOR;
entry._isPseudoRoot = false;
entry._size = desc.nFileSizeHigh * (static_cast<size_t>(MAXDWORD) + 1) + desc.nFileSizeLow;
myList.emplace_back(make_unique<FSNodeWINDOWS>(entry));
}
while (FindNextFile(handle, &desc));
FindClose(handle);
}
@ -152,37 +176,6 @@ bool FSNodeWINDOWS::getChildren(AbstractFSList& myList, ListMode mode) const
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FSNodeWINDOWS::addFile(AbstractFSList& list, ListMode mode,
const string& base, const WIN32_FIND_DATA& find_data)
{
const char* const asciiName = find_data.cFileName;
// Skip files starting with '.' (we assume empty filenames never occur)
if (asciiName[0] == '.')
return;
const bool isDirectory = static_cast<bool>(find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
const bool isFile = !isDirectory;//(find_data->dwFileAttributes & FILE_ATTRIBUTE_NORMAL ? true : false);
if ((isFile && mode == FSNode::ListMode::DirectoriesOnly) ||
(isDirectory && mode == FSNode::ListMode::FilesOnly))
return;
FSNodeWINDOWS entry;
entry._isDirectory = isDirectory;
entry._isFile = isFile;
entry._displayName = asciiName;
entry._path = base;
entry._path += asciiName;
if (entry._isDirectory)
entry._path += FSNode::PATH_SEPARATOR;
entry._isPseudoRoot = false;
entry._size = find_data.nFileSizeHigh * (static_cast<size_t>(MAXDWORD) + 1) + find_data.nFileSizeLow;
list.emplace_back(make_unique<FSNodeWINDOWS>(entry));
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool FSNodeWINDOWS::exists() const
{

View File

@ -77,18 +77,6 @@ class FSNodeWINDOWS : public AbstractFSNode
*/
bool setFlags();
/**
* Adds a single FSNodeWINDOWS to a given list.
* This method is used by getChildren() to populate the directory entries list.
*
* @param list List to put the file entry node in.
* @param mode Mode to use while adding the file entry to the list.
* @param base String with the directory being listed.
* @param find_data Describes a file that the FindFirstFile, FindFirstFileEx, or FindNextFile functions find.
*/
static void addFile(AbstractFSList& list, ListMode mode,
const string& base, const WIN32_FIND_DATA& find_data);
private:
string _displayName, _path;
bool _isPseudoRoot{false}, _isDirectory{false}, _isFile{false};