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 3558704ed5.
Pick-to: 6.4
Change-Id: Iad48eca4eef77011d4094125670ea302e8beae46
Reviewed-by: Jonas Karlsson <jonas.karlsson@qt.io>
bb10
parent
20d1477c14
commit
1501f45c33
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue