Dedupe QMetaObject::cast

By implementing in terms of QMetaObject::inherits().

Change-Id: I39a039539b05a20bc1713bd450d8a998c78433aa
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Sean Harmer 2016-03-11 11:50:50 +00:00
parent aa21ac1043
commit ad9726d99c

View File

@ -363,14 +363,7 @@ QObject *QMetaObject::cast(QObject *obj) const
*/
const QObject *QMetaObject::cast(const QObject *obj) const
{
if (obj) {
const QMetaObject *m = obj->metaObject();
do {
if (m == this)
return obj;
} while ((m = m->d.superdata));
}
return 0;
return (obj && obj->metaObject()->inherits(this)) ? obj : nullptr;
}
#ifndef QT_NO_TRANSLATION