From 2ede08bce669ddb68070ec1344a51b97ddc945d2 Mon Sep 17 00:00:00 2001 From: Janne Koskinen Date: Wed, 17 Jun 2009 15:42:12 +0200 Subject: Revert "Removed accidental allocation in QRingBuffer::clear()" This reverts commit 85e940d2fa5e8d2caf0d157f214bb826fc392e7b. --- src/corelib/tools/qringbuffer_p.h | 12 +++--------- 1 file 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; -- cgit v0.12