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>bb10
parent
a1bfac287e
commit
be04a47a8b
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue