From c3d8ab78b8bc63cc15b56719fc7bf2ec42c800de Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Thu, 2 Jul 2015 10:55:02 +0300 Subject: 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 Reviewed-by: Oswald Buddenhagen --- src/corelib/tools/qringbuffer_p.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/corelib/tools/qringbuffer_p.h') diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h index e7e80bc02c..3a5ae1c4cc 100644 --- a/src/corelib/tools/qringbuffer_p.h +++ b/src/corelib/tools/qringbuffer_p.h @@ -54,9 +54,7 @@ class QRingBuffer { public: explicit inline QRingBuffer(int growth = 4096) : - head(0), tail(0), tailBuffer(0), basicBlockSize(growth), bufferSize(0) { - buffers.append(QByteArray()); - } + head(0), tail(0), tailBuffer(0), basicBlockSize(growth), bufferSize(0) { } inline qint64 nextDataBlockSize() const { return (tailBuffer == 0 ? tail : buffers.first().size()) - head; -- cgit v1.2.3