summaryrefslogtreecommitdiffstats
path: root/src/gui/painting/qdatabuffer_p.h
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2010-05-07 06:15:37 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2010-05-07 06:15:37 (GMT)
commit4976130171033abdd8323a19229dcbfc5b008cfe (patch)
tree06fb286c8831e943941a9dabf081fe704fcfda88 /src/gui/painting/qdatabuffer_p.h
parent65d04843759d14f15f559c78df94626568bc0cb8 (diff)
downloadQt-4976130171033abdd8323a19229dcbfc5b008cfe.zip
Qt-4976130171033abdd8323a19229dcbfc5b008cfe.tar.gz
Qt-4976130171033abdd8323a19229dcbfc5b008cfe.tar.bz2
Avoid many unnecessary allocations, so so that paint engines attached to pixmaps
do not consume excessive amounts of memory, and so can still be reasonably kept cached with the pixmap. Saves 8K for every pixmaps drawn to on raster paint engine. Saves about 2K for other graphicssystems. Task-number: QTBUG-10215 Reviewed-by: Gunnar
Diffstat (limited to 'src/gui/painting/qdatabuffer_p.h')
-rw-r--r--src/gui/painting/qdatabuffer_p.h19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/gui/painting/qdatabuffer_p.h b/src/gui/painting/qdatabuffer_p.h
index bc5f1ef..8f8544f 100644
--- a/src/gui/painting/qdatabuffer_p.h
+++ b/src/gui/painting/qdatabuffer_p.h
@@ -60,16 +60,20 @@ QT_BEGIN_NAMESPACE
template <typename Type> class QDataBuffer
{
public:
- QDataBuffer(int res = 64)
+ QDataBuffer(int res)
{
capacity = res;
- buffer = (Type*) qMalloc(capacity * sizeof(Type));
+ if (res)
+ buffer = (Type*) qMalloc(capacity * sizeof(Type));
+ else
+ buffer = 0;
siz = 0;
}
~QDataBuffer()
{
- qFree(buffer);
+ if (buffer)
+ qFree(buffer);
}
inline void reset() { siz = 0; }
@@ -104,6 +108,8 @@ public:
inline void reserve(int size) {
if (size > capacity) {
+ if (capacity == 0)
+ capacity = 1;
while (capacity < size)
capacity *= 2;
buffer = (Type*) qRealloc(buffer, capacity * sizeof(Type));
@@ -112,7 +118,12 @@ public:
inline void shrink(int size) {
capacity = size;
- buffer = (Type*) qRealloc(buffer, capacity * sizeof(Type));
+ if (size)
+ buffer = (Type*) qRealloc(buffer, capacity * sizeof(Type));
+ else {
+ qFree(buffer);
+ buffer = 0;
+ }
}
inline void swap(QDataBuffer<Type> &other) {