summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2015-07-02 10:55:02 +0300
committerAlex Trotsenko <alex1973tr@gmail.com>2015-08-27 14:42:37 +0000
commitc3d8ab78b8bc63cc15b56719fc7bf2ec42c800de (patch)
tree3dba35c39908272b63d26fecd732cc6f35d8c159 /tests/auto/corelib
parent61ad604ad41607be97efea5a18cd4d9fb7ddca73 (diff)
QRingBuffer: avoid allocation in c'tor
Reduces creation time and memory consumption when the buffer is unused. Robin's benchmark: QBENCHMARK { QFile file(filename); } reports the following results (run with -median 10 -iterations 524288): before: 0.00028 msecs per iteration (total: 149, iterations: 524288) after: 0.00017 msecs per iteration (total: 93, iterations: 524288). Change-Id: Ied4e7caeca794b94260b8fc59b3ba656f4719c30 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp
index 74b6edf11f..2695e6238c 100644
--- a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp
+++ b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp
@@ -39,11 +39,11 @@ class tst_QRingBuffer : public QObject
{
Q_OBJECT
private slots:
+ void constructing();
void readPointerAtPositionWriteRead();
void readPointerAtPositionEmptyRead();
void readPointerAtPositionWithHead();
void readPointerAtPositionReadTooMuch();
- void sizeWhenEmpty();
void sizeWhenReservedAndChopped();
void sizeWhenReserved();
void free();
@@ -57,6 +57,23 @@ private slots:
void readLine();
};
+void tst_QRingBuffer::constructing()
+{
+ QRingBuffer ringBuffer;
+
+ QCOMPARE(ringBuffer.size(), Q_INT64_C(0));
+ QVERIFY(ringBuffer.isEmpty());
+ QCOMPARE(ringBuffer.nextDataBlockSize(), Q_INT64_C(0));
+ QVERIFY(ringBuffer.readPointer() == Q_NULLPTR);
+ QCOMPARE(ringBuffer.skip(5), Q_INT64_C(0));
+ QCOMPARE(ringBuffer.read(), QByteArray());
+ QCOMPARE(ringBuffer.getChar(), -1);
+ QVERIFY(!ringBuffer.canReadLine());
+
+ char buf[5];
+ QCOMPARE(ringBuffer.peek(buf, sizeof(buf)), Q_INT64_C(0));
+}
+
void tst_QRingBuffer::sizeWhenReserved()
{
QRingBuffer ringBuffer;
@@ -74,13 +91,6 @@ void tst_QRingBuffer::sizeWhenReservedAndChopped()
QCOMPARE(ringBuffer.size(), Q_INT64_C(0));
}
-void tst_QRingBuffer::sizeWhenEmpty()
-{
- QRingBuffer ringBuffer;
-
- QCOMPARE(ringBuffer.size(), Q_INT64_C(0));
-}
-
void tst_QRingBuffer::readPointerAtPositionReadTooMuch()
{
QRingBuffer ringBuffer;