diff options
| author | Thiago Macieira <thiago.macieira@intel.com> | 2025-08-14 16:58:11 -0700 |
|---|---|---|
| committer | Thiago Macieira <thiago.macieira@intel.com> | 2025-08-30 11:56:25 -0700 |
| commit | 43b9b1899b25339c82d9ab23274687f1f989e36c (patch) | |
| tree | 1519cd4e954b8f725ad4e8d12a5daafd1f6e0a9a /src/corelib/io/qbuffer.cpp | |
| parent | 23ec36d1b23a866771ada3a6f2cd47217fecad2c (diff) | |
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 <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/corelib/io/qbuffer.cpp')
| -rw-r--r-- | src/corelib/io/qbuffer.cpp | 22 |
1 files changed, 7 insertions, 15 deletions
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<qint64>(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; |
