From 6d614b5deac0d1605c61c8edf932d08b21a91bce Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Sun, 24 Feb 2002 19:55:24 +0000 Subject: Rewrite to reduce the number of strcmps. Sun Feb 24 13:40:55 2002 Owen Taylor * pango/pangoxft-fontmap.c (pango_xft_pattern_equal): Rewrite to reduce the number of strcmps. * pango/pangoxft-fontmap.c (pango_xft_font_map_load_font): Compute the patterns as for load_fontset(), then just return the first. This takes advantage of our caching strategy. --- pango/pangoxft-fontmap.c | 85 +++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 44 deletions(-) (limited to 'pango') diff --git a/pango/pangoxft-fontmap.c b/pango/pangoxft-fontmap.c index 62be892e..bd7c2ec0 100644 --- a/pango/pangoxft-fontmap.c +++ b/pango/pangoxft-fontmap.c @@ -520,59 +520,19 @@ pango_xft_font_map_new_font (PangoFontMap *fontmap, return (PangoFont *)_pango_xft_font_new (fontmap, XftPatternDuplicate (match)); } -static PangoFont * -pango_xft_font_map_load_font (PangoFontMap *fontmap, - PangoContext *context, - const PangoFontDescription *description) -{ - PangoXftFontMap *xfontmap = (PangoXftFontMap *)fontmap; - XftPattern *pattern, *match; - XftResult res; - PangoFont *font = NULL; - - pattern = pango_xft_make_pattern (description); - - match = XftFontMatch (xfontmap->display, xfontmap->screen, pattern, &res); - - XftPatternDestroy (pattern); - - if (match) - { - font = pango_xft_font_map_new_font (fontmap, match); - XftPatternDestroy (match); - } - - return font; -} - - -static void -pango_xft_font_set_free (PangoXftPatternSet *font_set) -{ - int i; - - for (i = 0; i < font_set->n_patterns; i++) - XftPatternDestroy (font_set->patterns[i]); - - g_free (font_set); -} - -static PangoFontset * -pango_xft_font_map_load_fontset (PangoFontMap *fontmap, - PangoContext *context, - const PangoFontDescription *desc, - PangoLanguage *language) +static PangoXftPatternSet * +pango_xft_font_map_get_patterns (PangoFontMap *fontmap, + PangoContext *context, + const PangoFontDescription *desc) { PangoXftFontMap *xfontmap = (PangoXftFontMap *)fontmap; XftPattern *pattern, *pattern_copy; XftPattern *match; - int i; char *family, *family_res; XftResult res; int id; GPtrArray *array; PangoXftPatternSet *patterns; - PangoFontsetSimple *simple; patterns = g_hash_table_lookup (xfontmap->fontset_hash, desc); @@ -642,7 +602,44 @@ pango_xft_font_map_load_fontset (PangoFontMap *fontmap, patterns); } + return patterns; +} + +static PangoFont * +pango_xft_font_map_load_font (PangoFontMap *fontmap, + PangoContext *context, + const PangoFontDescription *description) +{ + PangoXftPatternSet *patterns = pango_xft_font_map_get_patterns (fontmap, context, description); + + if (patterns->n_patterns > 0) + return pango_xft_font_map_new_font (fontmap, patterns->patterns[0]); + + return NULL; +} + +static void +pango_xft_font_set_free (PangoXftPatternSet *font_set) +{ + int i; + for (i = 0; i < font_set->n_patterns; i++) + XftPatternDestroy (font_set->patterns[i]); + + g_free (font_set); +} + + +static PangoFontset * +pango_xft_font_map_load_fontset (PangoFontMap *fontmap, + PangoContext *context, + const PangoFontDescription *desc, + PangoLanguage *language) +{ + PangoFontsetSimple *simple; + int i; + PangoXftPatternSet *patterns = pango_xft_font_map_get_patterns (fontmap, context, desc); + simple = pango_fontset_simple_new (language); for (i = 0; i < patterns->n_patterns; i++) -- cgit v1.2.1