diff options
| author | Ivan Solovev <ivan.solovev@qt.io> | 2024-01-29 14:36:10 +0100 |
|---|---|---|
| committer | Ivan Solovev <ivan.solovev@qt.io> | 2024-02-07 15:02:19 +0100 |
| commit | be04a47a8b371a44b728f7b7a2be2f66749e562b (patch) | |
| tree | c09a497e3a031af02bb7a2d03eca06420da24537 /src/corelib/serialization/qdatastream.cpp | |
| parent | a1bfac287ee5d3719646d68dc91dc8e8e4cec04e (diff) | |
QDataStream::readBytes(): only chunk when data is not all available
If the underlying QDataStream's device already contains all data that
we want to read, we can optimize the allocation algorithm, and try to
allocate all needed memory at once.
Use bytesAvailable() to determine if the underlying device can provide
all requested data, and adjust the initial block size based on the
result. If not all data is available, fall back to the geometric
growth algorithm.
Change-Id: I6384d2caa16c238c2dbb77b2ad761cbd8a44df6c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/serialization/qdatastream.cpp')
| -rw-r--r-- | src/corelib/serialization/qdatastream.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/corelib/serialization/qdatastream.cpp b/src/corelib/serialization/qdatastream.cpp index 32f827c69e7..fd550cf8bcf 100644 --- a/src/corelib/serialization/qdatastream.cpp +++ b/src/corelib/serialization/qdatastream.cpp @@ -1074,7 +1074,7 @@ QDataStream &QDataStream::readBytes(char *&s, qint64 &l) return *this; } - qsizetype step = 1024 * 1024; + qsizetype step = (dev->bytesAvailable() >= len) ? len : 1024 * 1024; qsizetype allocated = 0; char *prevBuf = nullptr; char *curBuf = nullptr; |
