From a5614264d5a5d6d1cc0f2773f4d7cd70195a0546 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Thu, 30 Jan 2014 05:46:35 +0200 Subject: Get rid of QGlyphLayout::advances_y ...and thus consume 4 bytes less per glyph and increase the performance a bit. It seems, the only CTFontGetAdvancesForGlyphs() returns both x and y advances, though y advances are always equal to 0 for horizontal orientation and x advances are always equal to 0 for vertical orientation. Also, rename `advances_x` to `advances` for consistency and declare QGlyphLayout's data size in a single place. Change-Id: I56b20f893f8a6feb7aa870e3edbca99dd93ba2e2 Reviewed-by: Eskil Abrahamsen Blomfeldt Reviewed-by: Lars Knoll Reviewed-by: Simon Hausmann --- src/gui/text/qtextengine_p.h | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) (limited to 'src/gui/text/qtextengine_p.h') diff --git a/src/gui/text/qtextengine_p.h b/src/gui/text/qtextengine_p.h index f2e16cf546..fce2bd808d 100644 --- a/src/gui/text/qtextengine_p.h +++ b/src/gui/text/qtextengine_p.h @@ -190,11 +190,15 @@ Q_DECLARE_TYPEINFO(QGlyphJustification, Q_PRIMITIVE_TYPE); struct QGlyphLayout { + enum { + SpaceNeeded = sizeof(glyph_t) + sizeof(QFixed) + sizeof(QFixedPoint) + + sizeof(QGlyphAttributes) + sizeof(QGlyphJustification) + }; + // init to 0 not needed, done when shaping QFixedPoint *offsets; // 8 bytes per element glyph_t *glyphs; // 4 bytes per element - QFixed *advances_x; // 4 bytes per element - QFixed *advances_y; // 4 bytes per element + QFixed *advances; // 4 bytes per element QGlyphJustification *justifications; // 4 bytes per element QGlyphAttributes *attributes; // 2 bytes per element @@ -208,9 +212,7 @@ struct QGlyphLayout int offset = totalGlyphs * sizeof(QFixedPoint); glyphs = reinterpret_cast(address + offset); offset += totalGlyphs * sizeof(glyph_t); - advances_x = reinterpret_cast(address + offset); - offset += totalGlyphs * sizeof(QFixed); - advances_y = reinterpret_cast(address + offset); + advances = reinterpret_cast(address + offset); offset += totalGlyphs * sizeof(QFixed); justifications = reinterpret_cast(address + offset); offset += totalGlyphs * sizeof(QGlyphJustification); @@ -221,8 +223,7 @@ struct QGlyphLayout inline QGlyphLayout mid(int position, int n = -1) const { QGlyphLayout copy = *this; copy.glyphs += position; - copy.advances_x += position; - copy.advances_y += position; + copy.advances += position; copy.offsets += position; copy.justifications += position; copy.attributes += position; @@ -233,27 +234,20 @@ struct QGlyphLayout return copy; } - static inline int spaceNeededForGlyphLayout(int totalGlyphs) { - return totalGlyphs * (sizeof(glyph_t) + sizeof(QGlyphAttributes) - + sizeof(QFixed) + sizeof(QFixed) + sizeof(QFixedPoint) - + sizeof(QGlyphJustification)); - } - inline QFixed effectiveAdvance(int item) const - { return (advances_x[item] + QFixed::fromFixed(justifications[item].space_18d6)) * !attributes[item].dontPrint; } + { return (advances[item] + QFixed::fromFixed(justifications[item].space_18d6)) * !attributes[item].dontPrint; } inline void clear(int first = 0, int last = -1) { if (last == -1) last = numGlyphs; if (first == 0 && last == numGlyphs && reinterpret_cast(offsets + numGlyphs) == reinterpret_cast(glyphs)) { - memset(offsets, 0, spaceNeededForGlyphLayout(numGlyphs)); + memset(offsets, 0, (numGlyphs * SpaceNeeded)); } else { const int num = last - first; memset(offsets + first, 0, num * sizeof(QFixedPoint)); memset(glyphs + first, 0, num * sizeof(glyph_t)); - memset(advances_x + first, 0, num * sizeof(QFixed)); - memset(advances_y + first, 0, num * sizeof(QFixed)); + memset(advances + first, 0, num * sizeof(QFixed)); memset(justifications + first, 0, num * sizeof(QGlyphJustification)); memset(attributes + first, 0, num * sizeof(QGlyphAttributes)); } @@ -272,7 +266,7 @@ private: typedef QVarLengthArray Array; public: QVarLengthGlyphLayoutArray(int totalGlyphs) - : Array(spaceNeededForGlyphLayout(totalGlyphs) / sizeof(void *) + 1) + : Array((totalGlyphs * SpaceNeeded) / sizeof(void *) + 1) , QGlyphLayout(reinterpret_cast(Array::data()), totalGlyphs) { memset(Array::data(), 0, Array::size() * sizeof(void *)); @@ -280,7 +274,7 @@ public: void resize(int totalGlyphs) { - Array::resize(spaceNeededForGlyphLayout(totalGlyphs) / sizeof(void *) + 1); + Array::resize((totalGlyphs * SpaceNeeded) / sizeof(void *) + 1); *((QGlyphLayout *)this) = QGlyphLayout(reinterpret_cast(Array::data()), totalGlyphs); memset(Array::data(), 0, Array::size() * sizeof(void *)); @@ -297,10 +291,7 @@ public: } private: - void *buffer[(N * (sizeof(glyph_t) + sizeof(QGlyphAttributes) - + sizeof(QFixed) + sizeof(QFixed) + sizeof(QFixedPoint) - + sizeof(QGlyphJustification))) - / sizeof(void *) + 1]; + void *buffer[(N * SpaceNeeded) / sizeof(void *) + 1]; }; struct QScriptItem; -- cgit v1.2.3