From 07057188e3e42246cf006b43963d0bdcdaa159f5 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Tue, 27 Jul 2021 16:03:23 +0200 Subject: QFileSystemModel: cache the name filters regexps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In order to filter out file names based on the user's settings, QFileSystemModel used to have a loop that tested if a given file name matched one of the filters. The problem is that each filter (a wildcard) was converted to a QRegularExpression _inside_ the loop. This causes a quadratic behavior (number of files * number of filters). Instead, build the regexps once when the filters are set (or the case sensitivity is changed, as that affects the filtering), and simply _use_ them in the loop. Simplify and correct some related code as a drive by. Done-with: Jean-Michaƫl Celerier Fixes: QTBUG-95383 Pick-to: 6.2 6.1 5.15 Change-Id: I6bc336364c145bb05793a8f867545d7715d35832 Reviewed-by: Samuel Gaist Reviewed-by: Qt CI Bot --- src/gui/itemmodels/qfilesystemmodel_p.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/gui/itemmodels/qfilesystemmodel_p.h') diff --git a/src/gui/itemmodels/qfilesystemmodel_p.h b/src/gui/itemmodels/qfilesystemmodel_p.h index 4acd6a92df..70468460e8 100644 --- a/src/gui/itemmodels/qfilesystemmodel_p.h +++ b/src/gui/itemmodels/qfilesystemmodel_p.h @@ -64,6 +64,8 @@ #include #include +#include + QT_REQUIRE_CONFIG(filesystemmodel); QT_BEGIN_NAMESPACE @@ -291,6 +293,8 @@ public: QHash bypassFilters; #if QT_CONFIG(regularexpression) QStringList nameFilters; + std::vector nameFiltersRegexps; + void rebuildNameFilterRegexps(); #endif QHash resolvedSymLinks; -- cgit v1.2.3