mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-25 18: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:
parent
90a5f82b92
commit
13f574bfb2
@ -74,14 +74,10 @@ static void moveNames(set<string, case_less>&& from, vector<string>& to)
|
||||
|
||||
void FileLister::browse(const string& path, bool clean)
|
||||
{
|
||||
set<string, case_less> directorySet;
|
||||
set<string, case_less> fileSet;
|
||||
if (!clean) {
|
||||
directorySet.insert(directories.begin(), directories.end());
|
||||
fileSet.insert(files.begin(), files.end());
|
||||
if (clean) {
|
||||
directories.clear();
|
||||
files.clear();
|
||||
}
|
||||
directories.clear();
|
||||
files.clear();
|
||||
|
||||
string slashedPath = path;
|
||||
if (path[path.length() - 1] != '/')
|
||||
@ -93,6 +89,9 @@ void FileLister::browse(const string& path, bool clean)
|
||||
return;
|
||||
}
|
||||
|
||||
set<string, case_less> directorySet;
|
||||
set<string, case_less> fileSet;
|
||||
|
||||
while (struct dirent *dptr = readdir(dirp)) {
|
||||
string file = dptr->d_name;
|
||||
|
||||
@ -155,8 +154,21 @@ void FileLister::browse(const string& path, bool clean)
|
||||
|
||||
closedir(dirp);
|
||||
|
||||
moveNames(move(directorySet), directories);
|
||||
moveNames(move(fileSet), files);
|
||||
if (!directorySet.empty()) {
|
||||
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()
|
||||
|
Loading…
Reference in New Issue
Block a user