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 <lars.knoll@digia.com>
This commit is contained in:
Simon Hausmann 2015-04-10 09:01:47 +02:00
parent 1aab68648d
commit d11665b27c
2 changed files with 19 additions and 14 deletions

View File

@ -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<QComposeTableElement>::const_iterator it =
std::lower_bound(m_composeTable.constBegin(), m_composeTable.constEnd(), m_composeBuffer, Compare());

View File

@ -70,6 +70,7 @@ private:
QVector<QComposeTableElement> m_composeTable;
uint m_composeBuffer[QT_KEYSEQUENCE_MAX_LEN + 1];
TableGenerator::TableState m_tableState;
bool m_compositionTableInitialized;
};
QT_END_NAMESPACE