From 6aa496c3665f8c337f5484515770dab47260c1fc Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 28 Nov 2013 09:07:36 +0100 Subject: Streamline font match() function. Determine writing system before executing the loop. Change-Id: I6c462bdef4d70860e76c7cc9d939e3e92983b173 Reviewed-by: Konstantin Ritt --- src/gui/text/qfontdatabase.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index 9ff23cd325..61c93dc2ac 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -499,6 +499,8 @@ static const int scriptForWritingSystem[] = { QChar::Script_Nko // Nko }; +Q_STATIC_ASSERT(sizeof(scriptForWritingSystem) / sizeof(scriptForWritingSystem[0]) == QFontDatabase::WritingSystemsCount); + int qt_script_for_writing_system(QFontDatabase::WritingSystem writingSystem) { return scriptForWritingSystem[writingSystem]; @@ -882,6 +884,8 @@ static int match(int script, const QFontDef &request, load(family_name, script); + const size_t writingSystem = std::find(scriptForWritingSystem, scriptForWritingSystem + QFontDatabase::WritingSystemsCount, script) - scriptForWritingSystem; + QFontDatabasePrivate *db = privateDb(); for (int x = 0; x < db->count; ++x) { if (blacklistedFamilies.contains(x)) @@ -896,17 +900,9 @@ static int match(int script, const QFontDef &request, if (family_name.isEmpty()) load(test.family->name, script); - bool supported = (script == QChar::Script_Common); - for (int ws = 1; !supported && ws < QFontDatabase::WritingSystemsCount; ++ws) { - if (scriptForWritingSystem[ws] != script) - continue; - if (test.family->writingSystems[ws] & QtFontFamily::Supported) - supported = true; - } - if (!supported) { - // family not supported in the script we want + // Check if family is supported in the script we want + if (script != QChar::Script_Common && !(test.family->writingSystems[writingSystem] & QtFontFamily::Supported)) continue; - } // as we know the script is supported, we can be sure // to find a matching font here. -- cgit v1.2.3