From 0e3ac20088d2b07a767e5379ffc68ad29e2e0150 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 1 Apr 2022 14:28:52 +0200 Subject: [PATCH] QCoreTextFontDatabase: remove 34 relocations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Tor Arne Vestbø --- src/gui/text/coretext/qcoretextfontdatabase.mm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/gui/text/coretext/qcoretextfontdatabase.mm b/src/gui/text/coretext/qcoretextfontdatabase.mm index fe7500b7f8..b47d406c37 100644 --- a/src/gui/text/coretext/qcoretextfontdatabase.mm +++ b/src/gui/text/coretext/qcoretextfontdatabase.mm @@ -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 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))