mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-26 02:08:28 +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:
parent
0b785770dc
commit
bd7eac32ba
@ -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;
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user