summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qringbuffer_p.h12
1 files changed, 3 insertions, 9 deletions
diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h
index d4d0af7..a1bfab0 100644
--- a/src/corelib/tools/qringbuffer_p.h
+++ b/src/corelib/tools/qringbuffer_p.h
@@ -62,10 +62,8 @@ class Q_CORE_EXPORT QRingBuffer
{
public:
inline QRingBuffer(int growth = 4096) : basicBlockSize(growth) {
- head = tail = 0;
- tailBuffer = 0;
- bufferSize = 0;
buffers << QByteArray();
+ clear();
}
inline int nextDataBlockSize() const {
@@ -106,12 +104,8 @@ public:
}
inline char *reserve(int bytes) {
- if (isEmpty()) {
- buffers[tailBuffer].resize(qMax(basicBlockSize, bytes));
- bufferSize = tail = bytes;
- return buffers[tailBuffer].data();
- }
bufferSize += bytes;
+
// if there is already enough space, simply return.
if (tail + bytes <= buffers.at(tailBuffer).size()) {
char *writePtr = buffers[tailBuffer].data() + tail;
@@ -204,7 +198,7 @@ public:
}
inline void clear() {
- if(!isEmpty()) {
+ if(!buffers.isEmpty()) {
QByteArray tmp = buffers[0];
buffers.clear();
buffers << tmp;