diff options
author | Janne Koskinen <janne.p.koskinen@digia.com> | 2009-05-20 07:20:09 (GMT) |
---|---|---|
committer | Janne Koskinen <janne.p.koskinen@digia.com> | 2009-05-20 07:20:09 (GMT) |
commit | 85e940d2fa5e8d2caf0d157f214bb826fc392e7b (patch) | |
tree | acfaf6f57777673a9a5101ece51a1915edcd3210 | |
parent | a819aa88e3aee10ffff595c0a1de139bf63e9526 (diff) | |
download | Qt-85e940d2fa5e8d2caf0d157f214bb826fc392e7b.zip Qt-85e940d2fa5e8d2caf0d157f214bb826fc392e7b.tar.gz Qt-85e940d2fa5e8d2caf0d157f214bb826fc392e7b.tar.bz2 |
Removed accidental allocation in QRingBuffer::clear()
-rw-r--r-- | src/corelib/tools/qringbuffer_p.h | 12 |
1 files 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; |