From d11665b27ce3357fb30bff6ffc1379a4756ec8d1 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 10 Apr 2015 09:01:47 +0200 Subject: Speed up application startup on X11 Avoid parsing the composition tables on application startup. Instead let's do that on-demand the first time a composition key is pressed. Change-Id: I52feb36246a091b9a84d46e479ba2ad1f5cd1556 Reviewed-by: Lars Knoll --- .../compose/qcomposeplatforminputcontext.cpp | 32 ++++++++++++---------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.cpp') diff --git a/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.cpp b/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.cpp index 49fa32004e..d1bea9af23 100644 --- a/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.cpp +++ b/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.cpp @@ -80,37 +80,32 @@ static const int composingKeys[] = { }; QComposeInputContext::QComposeInputContext() + : m_tableState(TableGenerator::EmptyTable) + , m_compositionTableInitialized(false) { - TableGenerator reader; - m_tableState = reader.tableState(); - - if ((m_tableState & TableGenerator::NoErrors) == TableGenerator::NoErrors) { - m_composeTable = reader.composeTable(); - clearComposeBuffer(); - } + clearComposeBuffer(); } bool QComposeInputContext::filterEvent(const QEvent *event) { - // if there were errors when generating the compose table input - // context should not try to filter anything, simply return false - if ((m_tableState & TableGenerator::NoErrors) != TableGenerator::NoErrors) - return false; - const QKeyEvent *keyEvent = (const QKeyEvent *)event; // should pass only the key presses if (keyEvent->type() != QEvent::KeyPress) { return false; } + // if there were errors when generating the compose table input + // context should not try to filter anything, simply return false + if (m_compositionTableInitialized && (m_tableState & TableGenerator::NoErrors) != TableGenerator::NoErrors) + return false; + int keyval = keyEvent->key(); int keysym = 0; if (ignoreKey(keyval)) return false; - QString text = keyEvent->text(); - if (!composeKey(keyval) && text.isEmpty()) + if (!composeKey(keyval) && keyEvent->text().isEmpty()) return false; keysym = keyEvent->nativeVirtualKey(); @@ -163,6 +158,15 @@ static bool isDuplicate(const QComposeTableElement &lhs, const QComposeTableElem bool QComposeInputContext::checkComposeTable() { + if (!m_compositionTableInitialized) { + TableGenerator reader; + m_tableState = reader.tableState(); + + if ((m_tableState & TableGenerator::NoErrors) == TableGenerator::NoErrors) + m_composeTable = reader.composeTable(); + + m_compositionTableInitialized = true; + } QVector::const_iterator it = std::lower_bound(m_composeTable.constBegin(), m_composeTable.constEnd(), m_composeBuffer, Compare()); -- cgit v1.2.3