summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2013-04-11 15:56:17 -0700
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-04-16 19:45:11 +0200
commitb4ce49287f9f8407e89f1e4485cc166368306c77 (patch)
treeb8b400e9a878da0f1bc8009cfd2a38a3c403de6a /src
parentfb1649d30b0542a69a534218e96950d0533dec8b (diff)
Make QBuffer::bytesAvailable() work
We don't need to keep an internal QBuffer position, we can just use the one from QIODevice::pos(). It will keep track of goings ahead and backwards for us, plus it will make the default bytesAvailable() work out-of-the-box too. This error was reported on IRC. Change-Id: I8559e8ee56edaa01ca8732c1f1012082ebe3a3f2 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com> Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/io/qbuffer.cpp19
1 files changed, 4 insertions, 15 deletions
diff --git a/src/corelib/io/qbuffer.cpp b/src/corelib/io/qbuffer.cpp
index 5975e01e76..4b7edd8481 100644
--- a/src/corelib/io/qbuffer.cpp
+++ b/src/corelib/io/qbuffer.cpp
@@ -61,7 +61,6 @@ public:
QByteArray *buf;
QByteArray defaultBuf;
- int ioIndex;
virtual qint64 peek(char *data, qint64 maxSize);
virtual QByteArray peek(qint64 maxSize);
@@ -157,14 +156,12 @@ QBuffer::QBuffer()
{
Q_D(QBuffer);
d->buf = &d->defaultBuf;
- d->ioIndex = 0;
}
QBuffer::QBuffer(QByteArray *buf)
: QIODevice(*new QBufferPrivate)
{
Q_D(QBuffer);
d->buf = buf ? buf : &d->defaultBuf;
- d->ioIndex = 0;
d->defaultBuf.clear();
}
#else
@@ -180,7 +177,6 @@ QBuffer::QBuffer(QObject *parent)
{
Q_D(QBuffer);
d->buf = &d->defaultBuf;
- d->ioIndex = 0;
}
/*!
@@ -206,7 +202,6 @@ QBuffer::QBuffer(QByteArray *byteArray, QObject *parent)
Q_D(QBuffer);
d->buf = byteArray ? byteArray : &d->defaultBuf;
d->defaultBuf.clear();
- d->ioIndex = 0;
}
#endif
@@ -253,7 +248,6 @@ void QBuffer::setBuffer(QByteArray *byteArray)
d->buf = &d->defaultBuf;
}
d->defaultBuf.clear();
- d->ioIndex = 0;
}
/*!
@@ -312,7 +306,6 @@ void QBuffer::setData(const QByteArray &data)
return;
}
*d->buf = data;
- d->ioIndex = 0;
}
/*!
@@ -340,7 +333,6 @@ bool QBuffer::open(OpenMode flags)
if ((flags & Truncate) == Truncate)
d->buf->resize(0);
- d->ioIndex = (flags & Append) == Append ? d->buf->size() : 0;
return QIODevice::open(flags);
}
@@ -390,7 +382,6 @@ bool QBuffer::seek(qint64 pos)
qWarning("QBuffer::seek: Invalid pos: %d", int(pos));
return false;
}
- d->ioIndex = int(pos);
return QIODevice::seek(pos);
}
@@ -420,10 +411,9 @@ bool QBuffer::canReadLine() const
qint64 QBuffer::readData(char *data, qint64 len)
{
Q_D(QBuffer);
- if ((len = qMin(len, qint64(d->buf->size()) - d->ioIndex)) <= 0)
+ if ((len = qMin(len, qint64(d->buf->size()) - pos())) <= 0)
return qint64(0);
- memcpy(data, d->buf->constData() + d->ioIndex, len);
- d->ioIndex += int(len);
+ memcpy(data, d->buf->constData() + pos(), len);
return len;
}
@@ -433,7 +423,7 @@ qint64 QBuffer::readData(char *data, qint64 len)
qint64 QBuffer::writeData(const char *data, qint64 len)
{
Q_D(QBuffer);
- int extraBytes = d->ioIndex + len - d->buf->size();
+ int extraBytes = pos() + len - d->buf->size();
if (extraBytes > 0) { // overflow
int newSize = d->buf->size() + extraBytes;
d->buf->resize(newSize);
@@ -443,8 +433,7 @@ qint64 QBuffer::writeData(const char *data, qint64 len)
}
}
- memcpy(d->buf->data() + d->ioIndex, (uchar *)data, int(len));
- d->ioIndex += int(len);
+ memcpy(d->buf->data() + pos(), (uchar *)data, int(len));
#ifndef QT_NO_QOBJECT
d->writtenSinceLastEmit += len;