QSlotObjectBase: make 'impl' and 'ref' private

This allows to fold the deref() and the destroy() operations into one,
destroyIfLastRef().

The member variables were renamed since there's now a member function
of the same name (ref()).

Change-Id: Ib94416d9e658065bbf5d3711ecafaf0eb063af17
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
Marc Mutz 2012-08-20 15:52:19 +02:00 committed by Qt by Nokia
parent 2d78e24191
commit e6c50609c8
2 changed files with 21 additions and 20 deletions

View File

@ -74,7 +74,7 @@ static int DIRECT_CONNECTION_ONLY = 0;
struct QSlotObjectBaseDeleter { // for use with QScopedPointer<QSlotObjectBase,...>
static void cleanup(QtPrivate::QSlotObjectBase *slot) {
if (slot && !slot->ref.deref() ) slot->destroy();
if (slot) slot->destroyIfLastRef();
}
};
static int *queuedConnectionTypes(const QList<QByteArray> &typeNames)
@ -444,7 +444,7 @@ QMetaCallEvent::QMetaCallEvent(QtPrivate::QSlotObjectBase *slotO, const QObject
callFunction_(0), method_offset_(0), method_relative_(ushort(-1))
{
if (slotObj_)
slotObj_->ref.ref();
slotObj_->ref();
}
/*!
@ -464,8 +464,8 @@ QMetaCallEvent::~QMetaCallEvent()
if (semaphore_)
semaphore_->release();
#endif
if (slotObj_ && !slotObj_->ref.deref())
slotObj_->destroy();
if (slotObj_)
slotObj_->destroyIfLastRef();
}
/*!
@ -869,8 +869,8 @@ QObjectPrivate::Connection::~Connection()
if (v != &DIRECT_CONNECTION_ONLY)
delete [] v;
}
if (isSlotObject && !slotObj->ref.deref())
slotObj->destroy();
if (isSlotObject)
slotObj->destroyIfLastRef();
}
@ -3426,7 +3426,7 @@ void QMetaObject::activate(QObject *sender, int signalOffset, int local_signal_i
const QObjectPrivate::StaticMetaCallFunction callFunction = c->callFunction;
const int method_relative = c->method_relative;
if (c->isSlotObject) {
c->slotObj->ref.ref();
c->slotObj->ref();
const QScopedPointer<QtPrivate::QSlotObjectBase, QSlotObjectBaseDeleter> obj(c->slotObj);
locker.unlock();
obj->call(receiver, argv ? argv : empty_argv);
@ -4205,8 +4205,8 @@ QMetaObject::Connection QObject::connectImpl(const QObject *sender, void **signa
{
if (!sender || !signal || !slotObj || !senderMetaObject) {
qWarning("QObject::connect: invalid null parametter");
if (slotObj && !slotObj->ref.deref())
slotObj->destroy();
if (slotObj)
slotObj->destroyIfLastRef();
return QMetaObject::Connection();
}
int signal_index = -1;
@ -4214,8 +4214,7 @@ QMetaObject::Connection QObject::connectImpl(const QObject *sender, void **signa
senderMetaObject->static_metacall(QMetaObject::IndexOfMethod, 0, args);
if (signal_index < 0 || signal_index >= QMetaObjectPrivate::get(senderMetaObject)->signalCount) {
qWarning("QObject::connect: signal not found in %s", senderMetaObject->className());
if (!slotObj->ref.deref())
slotObj->destroy();
slotObj->destroyIfLastRef();
return QMetaObject::Connection(0);
}
signal_index += QMetaObjectPrivate::signalOffset(senderMetaObject);
@ -4234,8 +4233,7 @@ QMetaObject::Connection QObject::connectImpl(const QObject *sender, void **signa
while (c2) {
if (c2->receiver == receiver && c2->isSlotObject && c2->slotObj->compare(slot)) {
if (!slotObj->ref.deref())
slotObj->destroy();
slotObj->destroyIfLastRef();
return QMetaObject::Connection();
}
c2 = c2->nextConnectionList;

View File

@ -101,13 +101,13 @@ namespace QtPrivate {
#endif
// internal base class (interface) containing functions required to call a slot managed by a pointer to function.
struct QSlotObjectBase {
QAtomicInt ref;
class QSlotObjectBase {
QAtomicInt m_ref;
// don't use virtual functions here; we don't want the
// compiler to create tons of per-polymorphic-class stuff that
// we'll never need. We just use one function pointer.
typedef void (*ImplFn)(int which, QSlotObjectBase* this_, QObject *receiver, void **args, bool *ret);
const ImplFn impl;
const ImplFn m_impl;
protected:
enum Operation {
Destroy,
@ -117,11 +117,14 @@ namespace QtPrivate {
NumOperations
};
public:
explicit QSlotObjectBase(ImplFn fn) : ref(1), impl(fn) {}
explicit QSlotObjectBase(ImplFn fn) : m_ref(1), m_impl(fn) {}
inline void destroy() { impl(Destroy, this, 0, 0, 0); }
inline bool compare(void **a) { bool ret; impl(Compare, this, 0, a, &ret); return ret; }
inline void call(QObject *r, void **a) { impl(Call, this, r, a, 0); }
inline int ref() Q_DECL_NOTHROW { return m_ref.ref(); }
inline void destroyIfLastRef() Q_DECL_NOTHROW
{ if (!m_ref.deref()) m_impl(Destroy, this, 0, 0, 0); }
inline bool compare(void **a) { bool ret; m_impl(Compare, this, 0, a, &ret); return ret; }
inline void call(QObject *r, void **a) { m_impl(Call, this, r, a, 0); }
protected:
~QSlotObjectBase() {}
};