summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorMarkus Goetz <Markus.Goetz@nokia.com>2009-09-22 11:15:56 (GMT)
committerMarkus Goetz <Markus.Goetz@nokia.com>2009-09-23 11:40:22 (GMT)
commit154f2ba23c87a0d316e3a9c263efa7dd3bbef6ce (patch)
tree4f68b54766383f2c05eceb4f516e4e13eab8fec0 /src/corelib
parentaf71faf8cb2c9cbf34c408b81ce7ae1ef6c6403e (diff)
downloadQt-154f2ba23c87a0d316e3a9c263efa7dd3bbef6ce.zip
Qt-154f2ba23c87a0d316e3a9c263efa7dd3bbef6ce.tar.gz
Qt-154f2ba23c87a0d316e3a9c263efa7dd3bbef6ce.tar.bz2
QRingBuffer: Try to minimize memory consumption while it is empty
Try not to hold an unused 4k QByteArray. This may introduce a performance regression e.g. for QNetworkReply in exchange for lower memory usage. We will see if this is really the case. Reviewed-by: Thiago
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/tools/qringbuffer_p.h23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h
index b2df054..c44346c 100644
--- a/src/corelib/tools/qringbuffer_p.h
+++ b/src/corelib/tools/qringbuffer_p.h
@@ -147,9 +147,20 @@ public:
--tailBuffer;
head = 0;
}
+
+ if (isEmpty())
+ clear(); // try to minify/squeeze us
}
inline char *reserve(int bytes) {
+ // if this is a fresh empty QRingBuffer
+ if (bufferSize == 0) {
+ buffers[0].resize(qMax(basicBlockSize, bytes));
+ bufferSize += bytes;
+ tail = bytes;
+ return buffers[tailBuffer].data();
+ }
+
bufferSize += bytes;
// if there is already enough space, simply return.
@@ -208,6 +219,9 @@ public:
--tailBuffer;
tail = buffers.at(tailBuffer).size();
}
+
+ if (isEmpty())
+ clear(); // try to minify/squeeze us
}
inline bool isEmpty() const {
@@ -244,11 +258,10 @@ public:
}
inline void clear() {
- if(!buffers.isEmpty()) {
- buffers.erase(buffers.begin() + 1, buffers.end());
- if (buffers.at(0).size() != basicBlockSize)
- buffers[0].resize(basicBlockSize);
- }
+ buffers.erase(buffers.begin() + 1, buffers.end());
+ buffers[0].resize(0);
+ buffers[0].squeeze();
+
head = tail = 0;
tailBuffer = 0;
bufferSize = 0;