Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

src: Improved performance of FilePathFilter #1030

Merged
merged 1 commit into from
May 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 1 addition & 8 deletions src/lib/project/SourceGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,7 @@ std::set<FilePath> SourceGroup::filterToContainedFilePaths(

if (isInIndexedPaths)
{
for (const FilePathFilter& excludeFilter: excludeFilters)
{
if (excludeFilter.isMatching(filePath))
{
isInIndexedPaths = false;
break;
}
}
isInIndexedPaths = !FilePathFilter::areMatching(excludeFilters, filePath);
}

if (isInIndexedPaths)
Expand Down
10 changes: 1 addition & 9 deletions src/lib/utility/file/FileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,5 @@ std::set<FilePath> FileManager::getAllSourceFilePaths() const

bool FileManager::isExcluded(const FilePath& filePath) const
{
for (const FilePathFilter& filter: m_excludeFilters)
{
if (filter.isMatching(filePath))
{
return true;
}
}

return false;
return FilePathFilter::areMatching(m_excludeFilters, filePath);
}
11 changes: 7 additions & 4 deletions src/lib/utility/file/FilePathFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ std::wstring FilePathFilter::wstr() const

bool FilePathFilter::isMatching(const FilePath& filePath) const
{
const std::wstring s = filePath.wstr();
std::wsmatch match;
return std::regex_match(s, match, m_filterRegex);
return isMatching(filePath.wstr());
}

bool FilePathFilter::isMatching(const std::wstring& fileStr) const
{
return std::regex_match(fileStr, m_filterRegex);
}

bool FilePathFilter::operator<(const FilePathFilter& other) const
Expand Down Expand Up @@ -96,5 +99,5 @@ std::wregex FilePathFilter::convertFilterStringToRegex(const std::wstring& filte
regexFilterString = std::regex_replace(regexFilterString, regex, L"[^\\\\/]*");
}

return std::wregex(regexFilterString);
return std::wregex(regexFilterString, std::regex::optimize);
}
20 changes: 20 additions & 0 deletions src/lib/utility/file/FilePathFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
class FilePathFilter
{
public:
template<typename ContainerType>
static bool areMatching(const ContainerType& filters, const FilePath& filePath);

explicit FilePathFilter(const std::wstring& filterString);

std::wstring wstr() const;

bool isMatching(const FilePath& filePath) const;
bool isMatching(const std::wstring& fileStr) const;

bool operator<(const FilePathFilter& other) const;

Expand All @@ -24,4 +28,20 @@ class FilePathFilter
std::wregex m_filterRegex;
};

template<typename ContainerType>
bool FilePathFilter::areMatching(const ContainerType& filters, const FilePath& filePath)
{
const std::wstring fileStr = filePath.wstr();

for (const FilePathFilter& filter: filters)
{
if (filter.isMatching(fileStr))
{
return true;
}
}

return false;
}

#endif // FILE_PATH_FILTER_H
9 changes: 1 addition & 8 deletions src/lib/utility/file/FileRegister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,7 @@ FileRegister::FileRegister(

if (ret)
{
for (const FilePathFilter& excludeFilter: m_excludeFilters)
{
if (excludeFilter.isMatching(filePath))
{
ret = false;
break;
}
}
ret = !FilePathFilter::areMatching(m_excludeFilters, filePath);
}
return ret;
})
Expand Down
11 changes: 1 addition & 10 deletions src/lib_cxx/project/SourceGroupCxxCdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,7 @@ std::set<FilePath> SourceGroupCxxCdb::getAllSourceFilePaths(
for (const FilePath& path: IndexerCommandCxx::getSourceFilesFromCDB(
cdb, m_settings->getCompilationDatabasePathExpandedAndAbsolute()))
{
bool excluded = false;
for (const FilePathFilter& filter: excludeFilters)
{
if (filter.isMatching(path))
{
excluded = true;
break;
}
}

bool excluded = FilePathFilter::areMatching(excludeFilters, path);
if (!excluded && path.exists())
{
sourceFilePaths.insert(path);
Expand Down
11 changes: 1 addition & 10 deletions src/lib_cxx/project/SourceGroupCxxCodeblocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,7 @@ std::set<FilePath> SourceGroupCxxCodeblocks::getAllSourceFilePaths() const
for (const FilePath& filePath:
project->getAllSourceFilePathsCanonical(m_settings->getSourceExtensions()))
{
bool isExcluded = false;
for (const FilePathFilter& excludeFilter: excludeFilters)
{
if (excludeFilter.isMatching(filePath))
{
isExcluded = true;
break;
}
}

bool isExcluded = FilePathFilter::areMatching(excludeFilters, filePath);
if (!isExcluded && filePath.exists())
{
sourceFilePaths.insert(filePath);
Expand Down