From 43b9b1899b25339c82d9ab23274687f1f989e36c Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 14 Aug 2025 16:58:11 -0700 Subject: QBuffer: replace Q_PRIVATE_SLOT with QMetaObject::invokeMethod There's a single call site, so this moves the effect closer to the cause and avoids a possible mistake in the string name. This delayed emission appears to exist so we "compress" the emission of those two signals and emit them only once, however many write() calls there may have been. We lose the vtable dispatch with this change, but that would only be a problem if a parent destructor (i.e., ~QIODevice()) posted events before ~QObject() cleared them. That is not the case now and unlikely to become so. Change-Id: I33cac248a651c88c7eb5fffd259f6b58a56d5d8a Reviewed-by: Volker Hilsheimer --- src/corelib/io/qbuffer.cpp | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'src/corelib/io/qbuffer.cpp') diff --git a/src/corelib/io/qbuffer.cpp b/src/corelib/io/qbuffer.cpp index f7984409a0e..adfacd1de77 100644 --- a/src/corelib/io/qbuffer.cpp +++ b/src/corelib/io/qbuffer.cpp @@ -25,26 +25,12 @@ public: QByteArray peek(qint64 maxSize) override; #ifndef QT_NO_QOBJECT - // private slots - void _q_emitSignals(); - qint64 writtenSinceLastEmit = 0; int signalConnectionCount = 0; bool signalsEmitted = false; #endif }; -#ifndef QT_NO_QOBJECT -void QBufferPrivate::_q_emitSignals() -{ - Q_Q(QBuffer); - emit q->bytesWritten(writtenSinceLastEmit); - writtenSinceLastEmit = 0; - emit q->readyRead(); - signalsEmitted = false; -} -#endif - qint64 QBufferPrivate::peek(char *data, qint64 maxSize) { qint64 readBytes = qMin(maxSize, static_cast(buf->size()) - pos); @@ -420,7 +406,13 @@ qint64 QBuffer::writeData(const char *data, qint64 len) d->writtenSinceLastEmit += len; if (d->signalConnectionCount && !d->signalsEmitted && !signalsBlocked()) { d->signalsEmitted = true; - QMetaObject::invokeMethod(this, "_q_emitSignals", Qt::QueuedConnection); + QMetaObject::invokeMethod(this, [](QBuffer *q) { + auto d = q->d_func(); + emit q->bytesWritten(d->writtenSinceLastEmit); + d->writtenSinceLastEmit = 0; + emit q->readyRead(); + d->signalsEmitted = false; + }, Qt::QueuedConnection, this); } #endif return len; -- cgit v1.2.3