diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2014-08-16 12:47:32 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-06-22 10:43:04 +0000 |
commit | 792f68adea6abd7e3c947a3a195c737efc36b760 (patch) | |
tree | 7e698ce75881b16e0bc3436aa02b2c683ad73efb /src | |
parent | 346c756dea650f88573f256d99f53257b59894d7 (diff) |
QTextureGlyphCache: don't use a QList<QImage>
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 <ritt.ks@gmail.com>
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/painting/qtextureglyphcache.cpp | 19 |
1 files 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<QImage> 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<images.size(); ++j) { - if (images.at(j) == img) { + for (int j = 0; j < numImages; ++j) { + if (images[j] == img) { found = true; break; } } if (!found) - images.append(img); + images[numImages++] = img; } } - return images.size(); + return numImages; } bool QTextureGlyphCache::populate(QFontEngine *fontEngine, int numGlyphs, const glyph_t *glyphs, |