1095QDataStream &QDataStream::readBytes(
char *&s, qint64 &l)
1101 qint64 length = readQSizeType(*
this);
1105 qsizetype len = qsizetype(length);
1106 if (length != len || length < 0) {
1107 setStatus(SizeLimitExceeded);
1111 qsizetype step = (dev->bytesAvailable() >= len) ? len : 1024 * 1024;
1112 qsizetype allocated = 0;
1113 std::unique_ptr<
char[]> curBuf =
nullptr;
1115 constexpr qsizetype StepIncreaseThreshold = std::numeric_limits<qsizetype>::max() / 2;
1117 qsizetype blockSize = qMin(step, len - allocated);
1118 const qsizetype n = allocated + blockSize + 1;
1119 if (
const auto prevBuf = std::exchange(curBuf, q20::make_unique_for_overwrite<
char[]>(n)))
1120 memcpy(curBuf.get(), prevBuf.get(), allocated);
1121 if (readBlock(curBuf.get() + allocated, blockSize) != blockSize)
1123 allocated += blockSize;
1124 if (step <= StepIncreaseThreshold)
1126 }
while (allocated < len);
1128 s = curBuf.release();