From 6f0814ab83317e8dcf13d9d94e6aaea5a68915f5 Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Thu, 18 Aug 2016 20:25:12 +0300 Subject: Micro-optimize QAbstractSocketPrivate::canReadNotification() Remove unnecessary checks in release build. Refactor the code. Change-Id: Ibee96790cbc8beb000757fc8e152fb4dcae9d506 Reviewed-by: Thiago Macieira --- src/network/socket/qabstractsocket.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'src/network') diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp index 662c8e957e..87ef31fb22 100644 --- a/src/network/socket/qabstractsocket.cpp +++ b/src/network/socket/qabstractsocket.cpp @@ -693,14 +693,6 @@ bool QAbstractSocketPrivate::canReadNotification() qDebug("QAbstractSocketPrivate::canReadNotification()"); #endif - if (!isBuffered) { - if (hasPendingData) { - socketEngine->setReadNotificationEnabled(false); - return true; - } - hasPendingData = true; - } - // If buffered, read data from the socket into the read buffer if (isBuffered) { const qint64 oldBufferSize = buffer.size(); @@ -730,18 +722,21 @@ bool QAbstractSocketPrivate::canReadNotification() // to indicate that the data was discarded. return !q->isReadable(); } + } else { + if (hasPendingData) { + socketEngine->setReadNotificationEnabled(false); + return true; + } + hasPendingData = true; } emitReadyRead(); - // If we were closed as a result of the readyRead() signal, - // return. - if (state == QAbstractSocket::UnconnectedState || state == QAbstractSocket::ClosingState) { #if defined (QABSTRACTSOCKET_DEBUG) + // If we were closed as a result of the readyRead() signal. + if (state == QAbstractSocket::UnconnectedState || state == QAbstractSocket::ClosingState) qDebug("QAbstractSocketPrivate::canReadNotification() socket is closing - returning"); #endif - return true; - } return true; } -- cgit v1.2.3