From 597e690c92243b47ac2191c8de8b12cd689bf2a6 Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Mon, 6 Jun 2011 13:52:04 +0200 Subject: don't reallocate memory if the old buffer has sufficient capacity Merge-request: 2627 Reviewed-by: Harald Fernengel --- src/gui/painting/qwindowsurface_qws.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/gui/painting/qwindowsurface_qws.cpp b/src/gui/painting/qwindowsurface_qws.cpp index 9d4f985..5bd56d3 100644 --- a/src/gui/painting/qwindowsurface_qws.cpp +++ b/src/gui/painting/qwindowsurface_qws.cpp @@ -964,10 +964,12 @@ void QWSLocalMemSurface::setGeometry(const QRect &rect) } else { const QImage::Format format = preferredImageFormat(win); const int bpl = nextMulOf4(bytesPerPixel(format) * size.width()); - if (memsize) + const int imagesize = bpl * size.height(); + if (memsize < imagesize) { delete[] mem; - memsize = bpl * size.height(); - mem = new uchar[memsize]; + memsize = imagesize; + mem = new uchar[memsize]; + } img = QImage(mem, size.width(), size.height(), bpl, format); setImageMetrics(img, win); } @@ -1132,8 +1134,6 @@ void QWSSharedMemSurface::setGeometry(const QRect &rect) mem.detach(); img = QImage(); } else { - mem.detach(); - QWidget *win = window(); const QImage::Format format = preferredImageFormat(win); const int bpl = nextMulOf4(bytesPerPixel(format) * size.width()); @@ -1142,9 +1142,12 @@ void QWSSharedMemSurface::setGeometry(const QRect &rect) #else const int imagesize = bpl * size.height(); #endif - if (!mem.create(imagesize)) { - perror("QWSSharedMemSurface::setGeometry allocating shared memory"); - qFatal("Error creating shared memory of size %d", imagesize); + if (mem.size() < imagesize) { + mem.detach(); + if (!mem.create(imagesize)) { + perror("QWSSharedMemSurface::setGeometry allocating shared memory"); + qFatal("Error creating shared memory of size %d", imagesize); + } } #ifdef QT_QWS_CLIENTBLIT *((uint *)mem.address()) = 0; -- cgit v0.12