Removing unnecessary chunking and stat'ing when reading QIODevice
commit302152bca4dc690574e1b841b60a343dba47e86a
authorJoão Abecasis <joao@abecasis.name>
Mon, 16 Nov 2009 16:38:18 +0000 (16 17:38 +0100)
committerJason McDonald <jason.mcdonald@nokia.com>
Thu, 19 Nov 2009 03:01:55 +0000 (19 13:01 +1000)
tree4979eba40cf5e5b64ff68b3e8363390a59ef6e6c
parentf68fa03ab06440d26b8e667fa3b65375d3fa0c00
Removing unnecessary chunking and stat'ing when reading QIODevice

Chunk size increased to QIODEVICE_BUFFERSIZE (currently 16k) where
chunking is still needed. Namely, on sequential devices and when
QByteArray is unable to allocate a large enough buffer. This is
necessary for backward compatibility

Improved validation and prevention of overflow in maxSize argument.

Updated autotest that relied on a null QByteArray when no data was
available and no errors were found. The only guarantee we should be
providing in this case is an empty result -- even though that behavior
is preserved for the time being.

Affected functions:

  * QIODevice::read(qint64 maxSize)

    Chunking will still happen for large maxSize (i.e., QByteArray
    resize fails), where it could be used as a synonym for
    QIODevice::readAll().

    No stat'ing performed. Read from device continues for as long as it
    is successful. Stops if an error occurs or if we get less data than
    requested.

  * QIODevice::readAll()

    Chunking is performed for sequential devices where total size
    wouldn't be known beforehand. For sequential devices, reading
    continues as long as data is returned, even if less than requested.

    Non-sequential devices will be stat'ed once. If QIODevice::size
    returns 0, this is taken to mean unknown size and chunking is
    performed.

    Otherwise, a single read request is made for the specified size. On
    failure to resize QByteArray, nothing is returned.

  * QIODevice::readLine(qint64 maxSize)

    Chunking is performed for maxSize == 0, or if we can't allocate a
    large enough buffer.

    No stat'ing performed at this level. Read from device continues
    until EOL is found, as long as we get all requested data.

Task-number: QT-2347
Reviewed-by: Thiago Macieira
Reviewed-by: Miikka Heikkinen
(cherry picked from commit 1e6b424b692b20dcfec920f8d3563e520ec1ff05)
src/corelib/io/qiodevice.cpp
tests/auto/qfile/tst_qfile.cpp