From 85e940d2fa5e8d2caf0d157f214bb826fc392e7b Mon Sep 17 00:00:00 2001 From: Janne Koskinen Date: Wed, 20 May 2009 09:20:09 +0200 Subject: Removed accidental allocation in QRingBuffer::clear() --- src/corelib/tools/qringbuffer_p.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h index 3a0901d..99c89f8 100644 --- a/src/corelib/tools/qringbuffer_p.h +++ b/src/corelib/tools/qringbuffer_p.h @@ -62,8 +62,10 @@ 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 { @@ -104,8 +106,12 @@ 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; @@ -198,7 +204,7 @@ public: } inline void clear() { - if(!buffers.isEmpty()) { + if(!isEmpty()) { QByteArray tmp = buffers[0]; buffers.clear(); buffers << tmp; -- cgit v0.12