From 09fba5cf3657c19c38e897a11a015d45b4328ae3 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 4 Jun 2020 17:39:20 +0200 Subject: [PATCH] QWindowsFontDatabase: port local QSets to QDuplicateTracker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apart from a more fitting, minimal, API, QDuplicateTracker also transparently uses C++17 pmr::monotonic_buffer_resource to avoid, or at least reduce, memory allocations. Change-Id: I155f5518190c5f8f6d21fbec3fcecd6bcc7ff852 Reviewed-by: Qt CI Bot Reviewed-by: MÃ¥rten Nordheim --- src/gui/text/windows/qwindowsfontdatabase.cpp | 7 +++---- src/gui/text/windows/qwindowsfontdatabase_ft.cpp | 10 +++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/gui/text/windows/qwindowsfontdatabase.cpp b/src/gui/text/windows/qwindowsfontdatabase.cpp index 58ff99e3a86..c89039ac58d 100644 --- a/src/gui/text/windows/qwindowsfontdatabase.cpp +++ b/src/gui/text/windows/qwindowsfontdatabase.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include @@ -499,7 +500,7 @@ namespace { {} QString populatedFontFamily; - QSet foundFontAndStyles; + QDuplicateTracker foundFontAndStyles; QWindowsFontDatabase *windowsFontDatabase; }; } @@ -642,10 +643,8 @@ static int QT_WIN_CALLBACK storeFont(const LOGFONT *logFont, const TEXTMETRIC *t signature = &reinterpret_cast(textmetric)->ntmFontSig; // We get a callback for each script-type supported, but we register them all // at once using the signature, so we only need one call to addFontToDatabase(). - FontAndStyle fontAndStyle = {familyName, styleName}; - if (sfp->foundFontAndStyles.contains(fontAndStyle)) + if (sfp->foundFontAndStyles.hasSeen({familyName, styleName})) return 1; - sfp->foundFontAndStyles.insert(fontAndStyle); } addFontToDatabase(familyName, styleName, *logFont, textmetric, signature, type, sfp); diff --git a/src/gui/text/windows/qwindowsfontdatabase_ft.cpp b/src/gui/text/windows/qwindowsfontdatabase_ft.cpp index e2c8d3455da..b149701de53 100644 --- a/src/gui/text/windows/qwindowsfontdatabase_ft.cpp +++ b/src/gui/text/windows/qwindowsfontdatabase_ft.cpp @@ -51,6 +51,8 @@ #if QT_CONFIG(regularexpression) #include #endif +#include + #include #include @@ -318,11 +320,9 @@ static int QT_WIN_CALLBACK storeFont(const LOGFONT *logFont, const TEXTMETRIC *t signature = &reinterpret_cast(textmetric)->ntmFontSig; // We get a callback for each script-type supported, but we register them all // at once using the signature, so we only need one call to addFontToDatabase(). - QSet *foundFontAndStyles = reinterpret_cast *>(lparam); - FontAndStyle fontAndStyle = {faceName, styleName}; - if (foundFontAndStyles->contains(fontAndStyle)) + auto foundFontAndStyles = reinterpret_cast *>(lparam); + if (foundFontAndStyles->hasSeen({faceName, styleName})) return 1; - foundFontAndStyles->insert(fontAndStyle); } addFontToDatabase(faceName, styleName, fullName, *logFont, textmetric, signature, type); @@ -352,7 +352,7 @@ void QWindowsFontDatabaseFT::populateFamily(const QString &familyName) lf.lfFaceName[familyName.size()] = 0; lf.lfCharSet = DEFAULT_CHARSET; lf.lfPitchAndFamily = 0; - QSet foundFontAndStyles; + QDuplicateTracker foundFontAndStyles; EnumFontFamiliesEx(dummy, &lf, storeFont, reinterpret_cast(&foundFontAndStyles), 0); ReleaseDC(0, dummy); }