Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plasma
Plasma Add-ons
Commits
5171bc3c
Commit
5171bc3c
authored
Feb 12, 2022
by
Waqar Ahmed
Browse files
Dictionary runner: initialize when needed
Avoid initalizing on startup, its costly and uneeded
parent
fd8934ad
Pipeline
#137900
passed with stage
in 3 minutes and 4 seconds
Changes
2
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
runners/dictionary/dictionaryrunner.cpp
View file @
5171bc3c
...
...
@@ -7,16 +7,20 @@
#include
<KLocalizedString>
#include
<QEventLoop>
#include
<QMutex>
#include
<QMutexLocker>
#include
<QStringList>
#include
<QTimer>
static
const
char
CONFIG_TRIGGERWORD
[]
=
"triggerWord"
;
namespace
{
const
char
CONFIG_TRIGGERWORD
[]
=
"triggerWord"
;
QMutex
s_initMutex
;
}
DictionaryRunner
::
DictionaryRunner
(
QObject
*
parent
,
const
KPluginMetaData
&
metaData
,
const
QVariantList
&
args
)
:
AbstractRunner
(
parent
,
metaData
,
args
)
{
m_engine
=
new
DictionaryMatchEngine
(
m_consumer
.
dataEngine
(
QStringLiteral
(
"dict"
)),
this
);
setPriority
(
LowPriority
);
setObjectName
(
QLatin1String
(
"Dictionary"
));
}
...
...
@@ -48,6 +52,25 @@ void DictionaryRunner::match(RunnerContext &context)
if
(
query
.
isEmpty
())
{
return
;
}
// Initialize engine
{
// It can happen that we are in this function and
// another match starts happening. Hence we lock to
// ensure that we always init the engine once
QMutexLocker
lock
(
&
s_initMutex
);
if
(
!
m_engine
)
{
QMetaObject
::
invokeMethod
(
this
,
[
this
]
{
m_consumer
=
std
::
make_unique
<
Plasma
::
DataEngineConsumer
>
();
m_engine
=
std
::
make_unique
<
DictionaryMatchEngine
>
(
m_consumer
->
dataEngine
(
QStringLiteral
(
"dict"
)));
},
Qt
::
BlockingQueuedConnection
);
}
}
QEventLoop
loop
;
QTimer
::
singleShot
(
400
,
&
loop
,
[
&
loop
]()
{
loop
.
quit
();
...
...
runners/dictionary/dictionaryrunner.h
View file @
5171bc3c
...
...
@@ -23,8 +23,8 @@ public:
private:
QString
m_triggerWord
;
DictionaryMatchEngine
*
m_engine
;
Plasma
::
DataEngineConsumer
m_consumer
;
std
::
unique_ptr
<
DictionaryMatchEngine
>
m_engine
;
std
::
unique_ptr
<
Plasma
::
DataEngineConsumer
>
m_consumer
;
protected
Q_SLOTS
:
void
init
()
override
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment