From 5fe210c7dba7c921b794da81b0a0cacbb51311b6 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Wed, 25 Aug 2021 08:20:44 +0200 Subject: [PATCH] Merge multiple ready read signals into one This minimizes the amount of readyRead() signals emitted. Change-Id: Ibd2409d6f273a2781839a73220cf41e57a941e54 Reviewed-by: hjk --- src/libs/utils/launchersocket.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/libs/utils/launchersocket.cpp b/src/libs/utils/launchersocket.cpp index d4c5a5dcbdb..69a366b20ad 100644 --- a/src/libs/utils/launchersocket.cpp +++ b/src/libs/utils/launchersocket.cpp @@ -81,9 +81,13 @@ public: , m_stdErr(stdErr) {} QByteArray stdOut() const { return m_stdOut; } QByteArray stdErr() const { return m_stdErr; } + void mergeWith(ReadyReadSignal *newSignal) { + m_stdOut += newSignal->stdOut(); + m_stdErr += newSignal->stdErr(); + } private: - const QByteArray m_stdOut; - const QByteArray m_stdErr; + QByteArray m_stdOut; + QByteArray m_stdErr; }; class FinishedSignal : public LauncherSignal @@ -245,7 +249,16 @@ void CallerHandle::appendSignal(LauncherSignal *launcherSignal) QMutexLocker locker(&m_mutex); QTC_ASSERT(isCalledFromLaunchersThread(), return); - // TODO: merge ReadyRead signals into one. + // Merge ReadyRead signals into one. + if (launcherSignal->signalType() == CallerHandle::SignalType::ReadyRead + && !m_signals.isEmpty() + && m_signals.last()->signalType() == CallerHandle::SignalType::ReadyRead) { + ReadyReadSignal *lastSignal = static_cast(m_signals.last()); + ReadyReadSignal *newSignal = static_cast(launcherSignal); + lastSignal->mergeWith(newSignal); + delete newSignal; + return; + } m_signals.append(launcherSignal); }