From bd7eac32ba3d18bae9d4d415e8738c73d0fa7f94 Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Wed, 13 Aug 2014 01:07:17 +0000 Subject: [PATCH] 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. --- src/filelister.cpp | 17 +++++++---------- src/filelister.h | 3 +-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/filelister.cpp b/src/filelister.cpp index fc3c6f0..4c67ee5 100644 --- a/src/filelister.cpp +++ b/src/filelister.cpp @@ -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 vfilter; - split(vfilter, filter, ","); - for (vector::iterator it = vfilter.begin(); it != vfilter.end(); ++it) { + for (vector::iterator it = filter.begin(); it != filter.end(); ++it) { if (file.find('.') == string::npos) { if (!it->empty()) continue; diff --git a/src/filelister.h b/src/filelister.h index 8da00db..a9d94b5 100644 --- a/src/filelister.h +++ b/src/filelister.h @@ -26,7 +26,7 @@ class FileLister { private: - std::string filter; + std::vector filter; bool showDirectories, showFiles; std::vector 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);