Commit 3a2e9c13 authored by Eike Ziller's avatar Eike Ziller
Browse files

FileSearch: Avoid copy of function object.



Converting std::unary_function to std::function will create a copy,
which we do not want. Actually std::unary_function as a base class
doesn't serve a purpose at all in this context, so we can just remove
it. Bind a std::function to a pointer to our search object instead.

Change-Id: I31db62312eefdff19b09fbb4eb20e8e666125874
Reviewed-by: default avatarDaniel Teske <daniel.teske@theqtcompany.com>
parent 0b91b77c
......@@ -83,7 +83,7 @@ bool openStream(const QString &filePath, QTextCodec *encoding, QTextStream *stre
return true;
}
class FileSearch : public std::unary_function<FileIterator::Item, FileSearchResultList>
class FileSearch
{
public:
FileSearch(const QString &searchTerm, QTextDocument::FindFlags flags,
......@@ -104,7 +104,7 @@ private:
bool wholeWord;
};
class FileSearchRegExp : public std::unary_function<FileIterator::Item, FileSearchResultList>
class FileSearchRegExp
{
public:
FileSearchRegExp(const QString &searchTerm, QTextDocument::FindFlags flags,
......@@ -370,8 +370,10 @@ void runFileSearch(QFutureInterface<FileSearchResultList> &future,
QTextDocument::FindFlags flags,
QMap<QString, QString> fileToContentsMap)
{
RunFileSearch search(future, searchTerm, files,
FileSearch(searchTerm, flags, fileToContentsMap, &future));
FileSearch searchFunction(searchTerm, flags, fileToContentsMap, &future);
RunFileSearch search(future, searchTerm, files, std::bind(&FileSearch::operator(),
&searchFunction,
std::placeholders::_1));
search.run();
}
......@@ -381,8 +383,10 @@ void runFileSearchRegExp(QFutureInterface<FileSearchResultList> &future,
QTextDocument::FindFlags flags,
QMap<QString, QString> fileToContentsMap)
{
RunFileSearch search(future, searchTerm, files,
FileSearchRegExp(searchTerm, flags, fileToContentsMap, &future));
FileSearchRegExp searchFunction(searchTerm, flags, fileToContentsMap, &future);
RunFileSearch search(future, searchTerm, files, std::bind(&FileSearchRegExp::operator(),
&searchFunction,
std::placeholders::_1));
search.run();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment