QCoreTextFontDatabase: remove 34 relocations

Same ole trick[1] as usual: Instead of an array of pointers (causing
relocations), declare an array of strings (char arrays; not causing
relocations).

[1] http://library.bagrintsev.me/CPP/dsohowto.pdf, Section 2.4.3.

As for storage requirements: We pay a few bytes per entry for extra
padding, as not all entries have length seven, but we save the
per-entry pointer variable, so sizeof(void*) bytes per entry, too, so
on 64-bit, at least, we're guaranteed to come out ahead.

Needed to replace nullptrs with empty strings here, and adjust the
sole user to check for emptiness instead of nullness.

Pick-to: 6.3 6.2
Task-number: QTBUG-100536
Change-Id: I4f07d72116eda2ebf1fdb327133f315417e2b0f0
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
bb10
Marc Mutz 2022-04-01 14:28:52 +02:00
parent c22bf34661
commit 0e3ac20088
1 changed files with 5 additions and 5 deletions

View File

@ -66,8 +66,8 @@ QT_BEGIN_NAMESPACE
// this could become a list of all languages used for each writing
// system, instead of using the single most common language.
static const char *languageForWritingSystem[] = {
0, // Any
static const char languageForWritingSystem[][8] = {
"", // Any
"en", // Latin
"el", // Greek
"ru", // Cyrillic
@ -97,12 +97,12 @@ static const char *languageForWritingSystem[] = {
"ja", // Japanese
"ko", // Korean
"vi", // Vietnamese
0, // Symbol
"", // Symbol
"sga", // Ogham
"non", // Runic
"man" // N'Ko
};
enum { LanguageCount = sizeof(languageForWritingSystem) / sizeof(const char *) };
enum { LanguageCount = sizeof languageForWritingSystem / sizeof *languageForWritingSystem };
QCoreTextFontDatabase::QCoreTextFontDatabase()
: m_hasPopulatedAliases(false)
@ -345,7 +345,7 @@ static void getFontDescription(CTFontDescriptorRef font, FontDescription *fd)
if (QCFType<CFArrayRef> languages = (CFArrayRef) CTFontDescriptorCopyAttribute(font, kCTFontLanguagesAttribute)) {
CFIndex length = CFArrayGetCount(languages);
for (int i = 1; i < LanguageCount; ++i) {
if (!languageForWritingSystem[i])
if (!*languageForWritingSystem[i])
continue;
QCFString lang = CFStringCreateWithCString(NULL, languageForWritingSystem[i], kCFStringEncodingASCII);
if (CFArrayContainsValue(languages, CFRangeMake(0, length), lang))