From ae9ee18cad4e9485ad53ac41916d7e2e77c3cbd1 Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Wed, 27 Aug 2014 16:43:52 +0300 Subject: [PATCH] QRingBuffer: optimize memory usage QByteArray resizing behavior is to preallocate a certain amount of memory for future growth. Make QRingBuffer aware of the extra capacity in QByteArray. Change-Id: I68310d5783fbc32e4fd5075ed3269ce6b7128a92 Reviewed-by: Thiago Macieira --- src/corelib/tools/qringbuffer_p.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h index 27d0791bd2..8fe56323a3 100644 --- a/src/corelib/tools/qringbuffer_p.h +++ b/src/corelib/tools/qringbuffer_p.h @@ -113,7 +113,7 @@ public: // if need buffer reallocation if (tail + bytes > buffers.last().size()) { - if (tail >= basicBlockSize) { + if (tail + bytes > buffers.last().capacity() && tail >= basicBlockSize) { // shrink this buffer to its current size buffers.last().resize(tail);