From 6ae96c3c1ddd6d3b7f8376a6b5f1ef2c5431b541 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Tue, 6 Jun 2023 16:07:14 +0300 Subject: [PATCH] kdecore: do not block while parsing files in KDeviceDatabase parsing ~30k lines and filling maps for the entries takes some time and could block the events of kinfocenter for example which is noticable because the parsing of files is delayed until a KDeviceDatabase query is made Signed-off-by: Ivailo Monev --- kdecore/util/kdevicedatabase.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kdecore/util/kdevicedatabase.cpp b/kdecore/util/kdevicedatabase.cpp index a4d559af..8eac0867 100644 --- a/kdecore/util/kdevicedatabase.cpp +++ b/kdecore/util/kdevicedatabase.cpp @@ -21,6 +21,9 @@ #include "kdebug.h" #include +#include + +#define KDEVICEDATABASE_TIMEOUT 100 struct KDeviceEntry { @@ -75,12 +78,19 @@ static void extractIDs(QFile *idsfile, { // qDebug() << Q_FUNC_INFO << idsfile->fileName(); + int counter = 0; char idbuffer[5]; char strbuffer[1024]; bool classessection = false; QByteArray lastvendorid; QByteArray lastdeviceid; while (!idsfile->atEnd()) { + counter++; + if (counter >= KDEVICEDATABASE_TIMEOUT) { + QCoreApplication::processEvents(QEventLoop::AllEvents, KDEVICEDATABASE_TIMEOUT); + counter = 0; + } + const QByteArray dbline = idsfile->readLine(); const QByteArray trimmeddbline = dbline.trimmed(); // qDebug() << Q_FUNC_INFO << dbline;