--- a/src/corelib/io/qiodevice.cpp Tue Jul 06 15:10:48 2010 +0300
+++ b/src/corelib/io/qiodevice.cpp Wed Aug 18 10:37:55 2010 +0300
@@ -1442,6 +1442,35 @@
return q_func()->write(&c, 1) == 1;
}
+/*!
+ \internal
+*/
+qint64 QIODevicePrivate::peek(char *data, qint64 maxSize)
+{
+ qint64 readBytes = q_func()->read(data, maxSize);
+ if (readBytes <= 0)
+ return readBytes;
+
+ buffer.ungetBlock(data, readBytes);
+ *pPos -= readBytes;
+ return readBytes;
+}
+
+/*!
+ \internal
+*/
+QByteArray QIODevicePrivate::peek(qint64 maxSize)
+{
+ QByteArray result = q_func()->read(maxSize);
+
+ if (result.isEmpty())
+ return result;
+
+ buffer.ungetBlock(result.constData(), result.size());
+ *pPos -= result.size();
+ return result;
+}
+
/*! \fn bool QIODevice::getChar(char *c)
Reads one character from the device and stores it in \a c. If \a c
@@ -1476,11 +1505,7 @@
*/
qint64 QIODevice::peek(char *data, qint64 maxSize)
{
- qint64 readBytes = read(data, maxSize);
- int i = readBytes;
- while (i > 0)
- ungetChar(data[i-- - 1]);
- return readBytes;
+ return d_func()->peek(data, maxSize);
}
/*!
@@ -1502,12 +1527,7 @@
*/
QByteArray QIODevice::peek(qint64 maxSize)
{
- QByteArray result = read(maxSize);
- int i = result.size();
- const char *data = result.constData();
- while (i > 0)
- ungetChar(data[i-- - 1]);
- return result;
+ return d_func()->peek(maxSize);
}
/*!