summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikhail Svetkin <mikhail.svetkin@qt.io>2019-01-03 09:56:18 +0100
committerMikhail Svetkin <mikhail.svetkin@qt.io>2019-01-07 12:46:56 +0000
commit4f598ff06276433c24600b7afbdfc35564216e09 (patch)
treeae190837dc83f5be14bca95029e8976161142276
parent87c47c6a82c7b6b40e248844feb23088d109f744 (diff)
Optimize allocation of QClipData::m_spans
Calculate the size of m_spans before allocate them. Change-Id: Ie572f243d6c167f42e807701bf9bf76a3c6c0c69 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r--src/gui/painting/qpaintengine_raster.cpp80
1 files changed, 39 insertions, 41 deletions
diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp
index 650fffbd76..0f5c7756ad 100644
--- a/src/gui/painting/qpaintengine_raster.cpp
+++ b/src/gui/painting/qpaintengine_raster.cpp
@@ -3882,51 +3882,15 @@ void QClipData::initialize()
Q_CHECK_PTR(m_clipLines);
QT_TRY {
- m_spans = (QSpan *)malloc(clipSpanHeight*sizeof(QSpan));
allocated = clipSpanHeight;
- Q_CHECK_PTR(m_spans);
-
QT_TRY {
- if (hasRectClip) {
- int y = 0;
- while (y < ymin) {
- m_clipLines[y].spans = 0;
- m_clipLines[y].count = 0;
- ++y;
- }
-
- const int len = clipRect.width();
- count = 0;
- while (y < ymax) {
- QSpan *span = m_spans + count;
- span->x = xmin;
- span->len = len;
- span->y = y;
- span->coverage = 255;
- ++count;
-
- m_clipLines[y].spans = span;
- m_clipLines[y].count = 1;
- ++y;
- }
-
- while (y < clipSpanHeight) {
- m_clipLines[y].spans = 0;
- m_clipLines[y].count = 0;
- ++y;
- }
- } else if (hasRegionClip) {
-
+ if (hasRegionClip) {
const auto rects = clipRegion.begin();
const int numRects = clipRegion.rectCount();
-
- { // resize
- const int maxSpans = (ymax - ymin) * numRects;
- if (maxSpans > allocated) {
- m_spans = q_check_ptr((QSpan *)realloc(m_spans, maxSpans * sizeof(QSpan)));
- allocated = maxSpans;
- }
- }
+ const int maxSpans = (ymax - ymin) * numRects;
+ allocated = qMax(allocated, maxSpans);
+ m_spans = (QSpan *)malloc(allocated * sizeof(QSpan));
+ Q_CHECK_PTR(m_spans);
int y = 0;
int firstInBand = 0;
@@ -3973,6 +3937,40 @@ void QClipData::initialize()
++y;
}
+ return;
+ }
+
+ m_spans = (QSpan *)malloc(allocated * sizeof(QSpan));
+ Q_CHECK_PTR(m_spans);
+
+ if (hasRectClip) {
+ int y = 0;
+ while (y < ymin) {
+ m_clipLines[y].spans = 0;
+ m_clipLines[y].count = 0;
+ ++y;
+ }
+
+ const int len = clipRect.width();
+ count = 0;
+ while (y < ymax) {
+ QSpan *span = m_spans + count;
+ span->x = xmin;
+ span->len = len;
+ span->y = y;
+ span->coverage = 255;
+ ++count;
+
+ m_clipLines[y].spans = span;
+ m_clipLines[y].count = 1;
+ ++y;
+ }
+
+ while (y < clipSpanHeight) {
+ m_clipLines[y].spans = 0;
+ m_clipLines[y].count = 0;
+ ++y;
+ }
}
} QT_CATCH(...) {
free(m_spans); // have to free m_spans again or someone might think that we were successfully initialized.