1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-22 13:05:20 +02:00

Avoid moving around entries unless new ones were found

When scanning multiple directories in succession, it's possible that
in some of them no matches are found. Avoid moving all pre-existing
entries back and forth in that case.

Also use move instead of copy for transferring the pre-existing
entries from the vector to the set.
This commit is contained in:
Maarten ter Huurne 2014-08-13 07:35:29 +02:00
parent 90a5f82b92
commit 13f574bfb2

View File

@ -74,14 +74,10 @@ static void moveNames(set<string, case_less>&& from, vector<string>& to)
void FileLister::browse(const string& path, bool clean) void FileLister::browse(const string& path, bool clean)
{ {
set<string, case_less> directorySet; if (clean) {
set<string, case_less> fileSet; directories.clear();
if (!clean) { files.clear();
directorySet.insert(directories.begin(), directories.end());
fileSet.insert(files.begin(), files.end());
} }
directories.clear();
files.clear();
string slashedPath = path; string slashedPath = path;
if (path[path.length() - 1] != '/') if (path[path.length() - 1] != '/')
@ -93,6 +89,9 @@ void FileLister::browse(const string& path, bool clean)
return; return;
} }
set<string, case_less> directorySet;
set<string, case_less> fileSet;
while (struct dirent *dptr = readdir(dirp)) { while (struct dirent *dptr = readdir(dirp)) {
string file = dptr->d_name; string file = dptr->d_name;
@ -155,8 +154,21 @@ void FileLister::browse(const string& path, bool clean)
closedir(dirp); closedir(dirp);
moveNames(move(directorySet), directories); if (!directorySet.empty()) {
moveNames(move(fileSet), files); for (string& dir : directories) {
directorySet.emplace(move(dir));
}
directories.clear();
moveNames(move(directorySet), directories);
}
if (!fileSet.empty()) {
for (string& file : files) {
fileSet.emplace(move(file));
}
files.clear();
moveNames(move(fileSet), files);
}
} }
unsigned int FileLister::size() unsigned int FileLister::size()