From 36a37b76d67304c134b5092023a1e6bd3e34220d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 10 Nov 2005 15:33:18 +0000 Subject: [PATCH] The font family list is now sorted - besides the obvious advantage for the user, this also allows binary searching the families (which is now done, too). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14826 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/app/FontManager.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/servers/app/FontManager.cpp b/src/servers/app/FontManager.cpp index e4bd0cc54c..26e4d25c5f 100644 --- a/src/servers/app/FontManager.cpp +++ b/src/servers/app/FontManager.cpp @@ -89,6 +89,13 @@ set_entry(node_ref& nodeRef, const char* name, BEntry& entry) } +static int +compare_font_families(const FontFamily* a, const FontFamily* b) +{ + return strcmp(a->Name(), b->Name()); +} + + // #pragma mark - @@ -426,7 +433,7 @@ FontManager::_AddFont(font_directory& directory, BEntry& entry) if (family == NULL) { family = new (nothrow) FontFamily(face->family_name, fNextID++); if (family == NULL - || !fFamilies.AddItem(family)) { + || !fFamilies.BinaryInsert(family, compare_font_families)) { delete family; FT_Done_Face(face); return B_NO_MEMORY; @@ -699,15 +706,9 @@ FontManager::_FindFamily(const char* name) const if (name == NULL) return NULL; - int32 count = fFamilies.CountItems(); - - for (int32 i = 0; i < count; i++) { - FontFamily* family = fFamilies.ItemAt(i); - if (!strcmp(family->Name(), name)) - return family; - } - - return NULL; + FontFamily family(name, 0); + return const_cast(fFamilies.BinarySearch(family, + compare_font_families)); }