From 1d9547c9a4b58cadc1105521df27e40ff5945259 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Tue, 11 Jul 2017 09:07:51 +0200 Subject: Don't indefinitely wait for data if it was able to read some data Passing -1 to waitForReadyRead() may cause it to wait for some time but the data retrieved may be enough for processing. So if 0 is passed from read, indicating that there is potentially more to come, then it will do a waitForReadyRead() then for more data to come. Change-Id: I75f270d1f124ecc12b18512cc20fb11f7a88f02e Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- src/xml/sax/qxml.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/xml/sax/qxml.cpp b/src/xml/sax/qxml.cpp index bc7d00483a..717a8c327d 100644 --- a/src/xml/sax/qxml.cpp +++ b/src/xml/sax/qxml.cpp @@ -1265,18 +1265,8 @@ void QXmlInputSource::fetchData() } else if (device->isOpen() || device->open(QIODevice::ReadOnly)) { rawData.resize(BufferSize); qint64 size = device->read(rawData.data(), BufferSize); - - if (size != -1) { - // We don't want to give fromRawData() less than four bytes if we can avoid it. - while (size < 4) { - if (!device->waitForReadyRead(-1)) - break; - int ret = device->read(rawData.data() + size, BufferSize - size); - if (ret <= 0) - break; - size += ret; - } - } + if (size == 0 && device->waitForReadyRead(-1)) + size = device->read(rawData.data(), BufferSize); rawData.resize(qMax(qint64(0), size)); } -- cgit v1.2.3