summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2016-07-13 15:39:38 +0300
committerAlex Trotsenko <alex1973tr@gmail.com>2016-07-23 09:05:04 +0000
commit3605fc653b3f54c9cda59fb3bf29b97d85ae0737 (patch)
treea387082f9779d8cde211351ca10a1c9297a7d3cf
parentb91f86a2128093ad7c65fa30b63ef87a9e55a4e0 (diff)
QRingBuffer: allow to change the chunk size of the buffer dynamically
Change-Id: I0ac55713c7bb8c48d2c9c774376543caef781980 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/io/qiodevice_p.h2
-rw-r--r--src/corelib/tools/qringbuffer_p.h8
-rw-r--r--tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp6
3 files changed, 16 insertions, 0 deletions
diff --git a/src/corelib/io/qiodevice_p.h b/src/corelib/io/qiodevice_p.h
index d264bfd31d..eed98a8fe3 100644
--- a/src/corelib/io/qiodevice_p.h
+++ b/src/corelib/io/qiodevice_p.h
@@ -92,6 +92,8 @@ public:
friend class QIODevicePrivate;
public:
// wrap functions from QRingBuffer
+ inline void setChunkSize(int size) { Q_ASSERT(m_buf); m_buf->setChunkSize(size); }
+ inline int chunkSize() const { Q_ASSERT(m_buf); return m_buf->chunkSize(); }
inline qint64 nextDataBlockSize() const { return (m_buf ? m_buf->nextDataBlockSize() : Q_INT64_C(0)); }
inline const char *readPointer() const { return (m_buf ? m_buf->readPointer() : Q_NULLPTR); }
inline const char *readPointerAtPosition(qint64 pos, qint64 &length) const { Q_ASSERT(m_buf); return m_buf->readPointerAtPosition(pos, length); }
diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h
index 44716cf4d3..325b71f267 100644
--- a/src/corelib/tools/qringbuffer_p.h
+++ b/src/corelib/tools/qringbuffer_p.h
@@ -67,6 +67,14 @@ public:
explicit inline QRingBuffer(int growth = QRINGBUFFER_CHUNKSIZE) :
head(0), tail(0), tailBuffer(0), basicBlockSize(growth), bufferSize(0) { }
+ inline void setChunkSize(int size) {
+ basicBlockSize = size;
+ }
+
+ inline int chunkSize() const {
+ return basicBlockSize;
+ }
+
inline qint64 nextDataBlockSize() const {
return (tailBuffer == 0 ? tail : buffers.first().size()) - head;
}
diff --git a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp
index c212589f59..4e14fd7a9b 100644
--- a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp
+++ b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp
@@ -58,6 +58,12 @@ void tst_QRingBuffer::constructing()
{
QRingBuffer ringBuffer;
+ const int chunkSize = ringBuffer.chunkSize();
+ ringBuffer.setChunkSize(0);
+ QCOMPARE(ringBuffer.chunkSize(), Q_INT64_C(0));
+ ringBuffer.setChunkSize(chunkSize);
+ QCOMPARE(ringBuffer.chunkSize(), chunkSize);
+
QCOMPARE(ringBuffer.size(), Q_INT64_C(0));
QVERIFY(ringBuffer.isEmpty());
QCOMPARE(ringBuffer.nextDataBlockSize(), Q_INT64_C(0));