From 792f68adea6abd7e3c947a3a195c737efc36b760 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 16 Aug 2014 12:47:32 +0200 Subject: [PATCH] QTextureGlyphCache: don't use a QList QImage is larger than a void*, so holding them in a QList is needlessly inefficient. In this case, the maximum size of the container is a small compile-time constant, so the best container to hold those QImages is a C array, even though it will default-construct all 12 QImages before even starting the loop, since the QImage constructor does not allocate memory. Change-Id: I83ca65aa1ca51c400ca696202d24cfaeab505a5b Reviewed-by: Konstantin Ritt Reviewed-by: Gunnar Sletta --- src/gui/painting/qtextureglyphcache.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/gui/painting/qtextureglyphcache.cpp b/src/gui/painting/qtextureglyphcache.cpp index 056fd8b701..360c3a3027 100644 --- a/src/gui/painting/qtextureglyphcache.cpp +++ b/src/gui/painting/qtextureglyphcache.cpp @@ -52,11 +52,14 @@ int QTextureGlyphCache::calculateSubPixelPositionCount(glyph_t glyph) const // Test 12 different subpixel positions since it factors into 3*4 so it gives // the coverage we need. - QList images; - for (int i=0; i<12; ++i) { + const int NumSubpixelPositions = 12; + + QImage images[NumSubpixelPositions]; + int numImages = 0; + for (int i = 0; i < NumSubpixelPositions; ++i) { QImage img = textureMapForGlyph(glyph, QFixed::fromReal(i / 12.0)); - if (images.isEmpty()) { + if (numImages == 0) { QPainterPath path; QFixedPoint point; m_current_fontengine->addGlyphsToPath(&glyph, &point, 1, &path, QTextItem::RenderFlags()); @@ -65,21 +68,21 @@ int QTextureGlyphCache::calculateSubPixelPositionCount(glyph_t glyph) const if (path.isEmpty()) break; - images.append(img); + images[numImages++] = img; } else { bool found = false; - for (int j=0; j