1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-19 07:15:55 +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) 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) 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()) if (std::find(files.begin(), files.end(), file) != files.end())
continue; continue;
if (filter.compare("*") == 0) { if (filter.empty()) {
files.push_back(file); files.push_back(file);
continue; continue;
} }
vector<string> vfilter; for (vector<string>::iterator it = filter.begin(); it != filter.end(); ++it) {
split(vfilter, filter, ",");
for (vector<string>::iterator it = vfilter.begin(); it != vfilter.end(); ++it) {
if (file.find('.') == string::npos) { if (file.find('.') == string::npos) {
if (!it->empty()) if (!it->empty())
continue; continue;

View File

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