diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qringbuffer_p.h | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h index ac33353..d4d0af7 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,9 +204,13 @@ public: } inline void clear() { - if(!buffers.isEmpty()) { - // remove all but the first - buffers.erase(buffers.begin() + 1, buffers.end()); + if(!isEmpty()) { + QByteArray tmp = buffers[0]; + buffers.clear(); + buffers << tmp; + //TODO merge this optimization ? + //buffers.erase(buffers.begin() + 1, buffers.end()); + //>>>>>>> 08ae7ee1fb930e7d4b4039e2294cba69f9380964:src/corelib/tools/qringbuffer_p.h if (buffers.at(0).size() != basicBlockSize) buffers[0].resize(basicBlockSize); } |