From 0873e5abb6cce584f5bebed013908ad998713f94 Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Sat, 2 Sep 2017 17:09:59 +0300 Subject: QProcess/Unix: do not toggle a state of the write notifier twice _q_canWrite() unconditionally disabled the write notifier before the writing, and might have enabled it again afterwards. This caused unnecessary processing in the event dispatcher and could result in extra system calls. Actually setting the state at the moment when the write buffer size is determined is enough. Change-Id: I81f9ec27d95a5a9bdb83cc6a842b6ae95f002b96 Reviewed-by: Edward Welbourne Reviewed-by: Joerg Bornemann Reviewed-by: Thiago Macieira --- src/corelib/io/qprocess.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 7ed319f5f1..41f4b2aa83 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -1090,10 +1090,9 @@ bool QProcessPrivate::_q_canReadStandardError() */ bool QProcessPrivate::_q_canWrite() { - if (stdinChannel.notifier) - stdinChannel.notifier->setEnabled(false); - if (writeBuffer.isEmpty()) { + if (stdinChannel.notifier) + stdinChannel.notifier->setEnabled(false); #if defined QPROCESS_DEBUG qDebug("QProcessPrivate::canWrite(), not writing anything (empty write buffer)."); #endif @@ -1102,10 +1101,10 @@ bool QProcessPrivate::_q_canWrite() const bool writeSucceeded = writeToStdin(); - if (stdinChannel.notifier && !writeBuffer.isEmpty()) - stdinChannel.notifier->setEnabled(true); if (writeBuffer.isEmpty() && stdinChannel.closed) closeWriteChannel(); + else if (stdinChannel.notifier) + stdinChannel.notifier->setEnabled(!writeBuffer.isEmpty()); return writeSucceeded; } -- cgit v1.2.3