summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-12-05 14:44:49 +0100
committerMarc Mutz <marc.mutz@qt.io>2022-12-07 07:24:14 +0100
commit1501f45c335f0a82843e3133ec2ef54d93546cf9 (patch)
tree80b6fde589816fb51392f769771a7bcb3c8f9ddf /src/gui
parent20d1477c14316a43b65415bae90d1e5d12fcbf44 (diff)
QFont: replace a QVLA with a C array
QVarLengthArray doesn't allocate, but is nevertheless dynamically initialized, incl. thread-safe static overhead. Turn the QVLA<QPair<int,int>> into a std::array<int,2>[] instead. This container has constant initialization and the use of array<int> instead of pair<int, int> means we can use the bool inverted argument as an index into the array instead of having to switch over .first and .second. Saves ~600B in text size and ~100B in BSS on optimized Clang 15 AMD64 Linux builds, and the copying, under mutex protection, of the data at runtime. Amends 3558704ed5c3d2c6dc6d024dfa454997469ca75f. Pick-to: 6.4 Change-Id: Iad48eca4eef77011d4094125670ea302e8beae46 Reviewed-by: Jonas Karlsson <jonas.karlsson@qt.io>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/text/qfont.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp
index 2b649a7dd8..0db9bbac3f 100644
--- a/src/gui/text/qfont.cpp
+++ b/src/gui/text/qfont.cpp
@@ -31,6 +31,8 @@
#include <QtCore/QMutexLocker>
#include <QtCore/QMutex>
+#include <array>
+
// #define QFONTCACHE_DEBUG
#ifdef QFONTCACHE_DEBUG
# define FC_DEBUG qDebug
@@ -140,7 +142,7 @@ Q_GUI_EXPORT int qt_defaultDpi()
/* Helper function to convert between legacy Qt and OpenType font weights. */
static int convertWeights(int weight, bool inverted)
{
- static const QVarLengthArray<QPair<int, int>, 9> legacyToOpenTypeMap = {
+ static constexpr std::array<int, 2> legacyToOpenTypeMap[] = {
{ 0, QFont::Thin }, { 12, QFont::ExtraLight }, { 25, QFont::Light },
{ 50, QFont::Normal }, { 57, QFont::Medium }, { 63, QFont::DemiBold },
{ 75, QFont::Bold }, { 81, QFont::ExtraBold }, { 87, QFont::Black },
@@ -151,8 +153,8 @@ static int convertWeights(int weight, bool inverted)
// Go through and find the closest mapped value
for (auto mapping : legacyToOpenTypeMap) {
- const int weightOld = inverted ? mapping.second : mapping.first;
- const int weightNew = inverted ? mapping.first : mapping.second;
+ const int weightOld = mapping[ inverted];
+ const int weightNew = mapping[!inverted];
const int dist = qAbs(weightOld - weight);
if (dist < closestDist) {
result = weightNew;