It should be more efficient to compare and ensure uniqueness of CFURLs rather than CFStrings, plus we avoid having to get file system paths for all the duplicated URLs. (On my system, 810 fonts turn into 355 unique font files).
There should be no behavioral changes from this.
From: Brendan Shanks bshanks@codeweavers.com
--- dlls/win32u/freetype.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/dlls/win32u/freetype.c b/dlls/win32u/freetype.c index a8a41f142c4..aeae190bc46 100644 --- a/dlls/win32u/freetype.c +++ b/dlls/win32u/freetype.c @@ -1360,10 +1360,14 @@ done:
static void load_mac_font_callback(const void *value, void *context) { - CFStringRef pathStr = value; + CFURLRef url = value; + CFStringRef pathStr; CFIndex len; char* path;
+ pathStr = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle); + if (!pathStr) return; + len = CFStringGetMaximumSizeOfFileSystemRepresentation(pathStr); path = malloc( len ); if (path && CFStringGetFileSystemRepresentation(pathStr, path, len)) @@ -1372,6 +1376,7 @@ static void load_mac_font_callback(const void *value, void *context) AddFontToList(NULL, path, NULL, 0, ADDFONT_EXTERNAL_FONT); } free( path ); + CFRelease(pathStr); }
static void load_mac_fonts(void) @@ -1381,7 +1386,7 @@ static void load_mac_fonts(void) CFDictionaryRef options; CTFontCollectionRef col; CFArrayRef descs; - CFMutableSetRef paths; + CFMutableSetRef urls; CFIndex i;
removeDupesKey = kCTFontCollectionRemoveDuplicatesOption; @@ -1404,8 +1409,8 @@ static void load_mac_fonts(void) return; }
- paths = CFSetCreateMutable(NULL, 0, &kCFTypeSetCallBacks); - if (!paths) + urls = CFSetCreateMutable(NULL, 0, &kCFTypeSetCallBacks); + if (!urls) { WARN("CFSetCreateMutable failed\n"); CFRelease(descs); @@ -1417,7 +1422,6 @@ static void load_mac_fonts(void) CTFontDescriptorRef desc; CFURLRef url; CFStringRef ext; - CFStringRef path;
desc = CFArrayGetValueAtIndex(descs, i); url = CTFontDescriptorCopyAttribute(desc, kCTFontURLAttribute); @@ -1436,18 +1440,14 @@ static void load_mac_fonts(void) } }
- path = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle); + CFSetAddValue(urls, url); CFRelease(url); - if (!path) continue; - - CFSetAddValue(paths, path); - CFRelease(path); }
CFRelease(descs);
- CFSetApplyFunction(paths, load_mac_font_callback, NULL); - CFRelease(paths); + CFSetApplyFunction(urls, load_mac_font_callback, NULL); + CFRelease(urls); }
#endif
This merge request was approved by Huw Davies.