1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-12-27 07:13:20 +02:00

Pre-process the filter string in FileLister::setFilter

Instead of splitting the filter for every file in FileLister::browse,
the filter is split immediately in FileLister::setFilter, improving
performance.

getFilter is removed because it was unused. This also removes the need
to update the return type to 'const std::vector&' in the method and
rewrite its callers.
This commit is contained in:
Nebuleon Fumika 2014-08-13 01:07:17 +00:00 committed by Maarten ter Huurne
parent 0b785770dc
commit bd7eac32ba
2 changed files with 8 additions and 12 deletions

View File

@ -40,14 +40,13 @@ FileLister::FileLister()
{
}
const string &FileLister::getFilter()
{
return filter;
}
void FileLister::setFilter(const string &filter)
{
this->filter = filter;
if (filter.empty() || filter == "*") {
this->filter.clear();
} else {
split(this->filter, filter, ",");
}
}
void FileLister::setShowDirectories(bool showDirectories)
@ -112,14 +111,12 @@ void FileLister::browse(const string& path, bool clean)
if (std::find(files.begin(), files.end(), file) != files.end())
continue;
if (filter.compare("*") == 0) {
if (filter.empty()) {
files.push_back(file);
continue;
}
vector<string> vfilter;
split(vfilter, filter, ",");
for (vector<string>::iterator it = vfilter.begin(); it != vfilter.end(); ++it) {
for (vector<string>::iterator it = filter.begin(); it != filter.end(); ++it) {
if (file.find('.') == string::npos) {
if (!it->empty())
continue;

View File

@ -26,7 +26,7 @@
class FileLister {
private:
std::string filter;
std::vector<std::string> filter;
bool showDirectories, showFiles;
std::vector<std::string> directories, files, excludes;
@ -43,7 +43,6 @@ public:
bool isFile(unsigned int);
bool isDirectory(unsigned int);
const std::string &getFilter();
void setFilter(const std::string &filter);
void setShowDirectories(bool);