Improve lookup speed for QAccessible::uniqueId
When QAccessible::uniqueId was called, it would call QHash::key(), which has linear time performance. This can cause application slowdown if a big number of QAccessibleInterface Ids have to be found. The patch adds an additional QHash to keep track of the inverse relationship from QAccessibleInterface pointers to their Ids. Change-Id: I975e3dc0e6c628e2ea701323d8b87184ad133cfb Task-number: QTBUG-54491 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>bb10
parent
3658354a7d
commit
b6c10cf331
|
|
@ -755,7 +755,7 @@ void QAccessible::deleteAccessibleInterface(Id id)
|
|||
*/
|
||||
QAccessible::Id QAccessible::uniqueId(QAccessibleInterface *iface)
|
||||
{
|
||||
Id id = QAccessibleCache::instance()->idToInterface.key(iface);
|
||||
Id id = QAccessibleCache::instance()->idForInterface(iface);
|
||||
if (!id)
|
||||
id = registerAccessibleInterface(iface);
|
||||
return id;
|
||||
|
|
@ -768,7 +768,7 @@ QAccessible::Id QAccessible::uniqueId(QAccessibleInterface *iface)
|
|||
*/
|
||||
QAccessibleInterface *QAccessible::accessibleInterface(Id id)
|
||||
{
|
||||
return QAccessibleCache::instance()->idToInterface.value(id);
|
||||
return QAccessibleCache::instance()->interfaceForId(id);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -77,6 +77,11 @@ QAccessibleInterface *QAccessibleCache::interfaceForId(QAccessible::Id id) const
|
|||
return idToInterface.value(id);
|
||||
}
|
||||
|
||||
QAccessible::Id QAccessibleCache::idForInterface(QAccessibleInterface *iface) const
|
||||
{
|
||||
return interfaceToId.value(iface);
|
||||
}
|
||||
|
||||
QAccessible::Id QAccessibleCache::insert(QObject *object, QAccessibleInterface *iface) const
|
||||
{
|
||||
Q_ASSERT(iface);
|
||||
|
|
@ -84,7 +89,7 @@ QAccessible::Id QAccessibleCache::insert(QObject *object, QAccessibleInterface *
|
|||
|
||||
// object might be 0
|
||||
Q_ASSERT(!objectToId.contains(object));
|
||||
Q_ASSERT_X(!idToInterface.values().contains(iface), "", "Accessible interface inserted into cache twice!");
|
||||
Q_ASSERT_X(!interfaceToId.contains(iface), "", "Accessible interface inserted into cache twice!");
|
||||
|
||||
QAccessible::Id id = acquireId();
|
||||
QObject *obj = iface->object();
|
||||
|
|
@ -94,6 +99,7 @@ QAccessible::Id QAccessibleCache::insert(QObject *object, QAccessibleInterface *
|
|||
connect(obj, &QObject::destroyed, this, &QAccessibleCache::objectDestroyed);
|
||||
}
|
||||
idToInterface.insert(id, iface);
|
||||
interfaceToId.insert(iface, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
|
|
@ -109,6 +115,7 @@ void QAccessibleCache::objectDestroyed(QObject* obj)
|
|||
void QAccessibleCache::deleteInterface(QAccessible::Id id, QObject *obj)
|
||||
{
|
||||
QAccessibleInterface *iface = idToInterface.take(id);
|
||||
interfaceToId.take(iface);
|
||||
if (!obj)
|
||||
obj = iface->object();
|
||||
if (obj)
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ class Q_GUI_EXPORT QAccessibleCache :public QObject
|
|||
public:
|
||||
static QAccessibleCache *instance();
|
||||
QAccessibleInterface *interfaceForId(QAccessible::Id id) const;
|
||||
QAccessible::Id idForInterface(QAccessibleInterface *iface) const;
|
||||
QAccessible::Id insert(QObject *object, QAccessibleInterface *iface) const;
|
||||
void deleteInterface(QAccessible::Id id, QObject *obj = 0);
|
||||
|
||||
|
|
@ -79,6 +80,7 @@ private:
|
|||
QAccessible::Id acquireId() const;
|
||||
|
||||
mutable QHash<QAccessible::Id, QAccessibleInterface *> idToInterface;
|
||||
mutable QHash<QAccessibleInterface *, QAccessible::Id> interfaceToId;
|
||||
mutable QHash<QObject *, QAccessible::Id> objectToId;
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
|
|
|
|||
Loading…
Reference in New Issue