Simplify QDataStream::skipRawData()
... by using the new QIODevice::skip() function. Change-Id: I943c4feb896d677f3150da542950595d7f485e75 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
3088f73cf4
commit
29ef0d2bcc
@ -1385,32 +1385,13 @@ int QDataStream::writeRawData(const char *s, int len)
|
|||||||
int QDataStream::skipRawData(int len)
|
int QDataStream::skipRawData(int len)
|
||||||
{
|
{
|
||||||
CHECK_STREAM_PRECOND(-1)
|
CHECK_STREAM_PRECOND(-1)
|
||||||
|
if (q_status != Ok && dev->isTransactionStarted())
|
||||||
if (dev->isSequential()) {
|
|
||||||
char buf[4096];
|
|
||||||
int sumRead = 0;
|
|
||||||
|
|
||||||
while (len > 0) {
|
|
||||||
int blockSize = qMin(len, (int)sizeof(buf));
|
|
||||||
int n = readBlock(buf, blockSize);
|
|
||||||
if (n == -1)
|
|
||||||
return -1;
|
return -1;
|
||||||
if (n == 0)
|
|
||||||
return sumRead;
|
|
||||||
|
|
||||||
sumRead += n;
|
const int skipResult = dev->skip(len);
|
||||||
len -= blockSize;
|
if (skipResult != len)
|
||||||
}
|
setStatus(ReadPastEnd);
|
||||||
return sumRead;
|
return skipResult;
|
||||||
} else {
|
|
||||||
qint64 pos = dev->pos();
|
|
||||||
qint64 size = dev->size();
|
|
||||||
if (pos + len > size)
|
|
||||||
len = size - pos;
|
|
||||||
if (!dev->seek(pos + len))
|
|
||||||
return -1;
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user