[pango/speed-up-format-filtering: 1/7] fc: Only do filtering by format once
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/speed-up-format-filtering: 1/7] fc: Only do filtering by format once
- Date: Sat, 22 Aug 2020 16:12:56 +0000 (UTC)
commit eea35d8996b51e332411840e6e9111c9902cf622
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Aug 16 08:17:50 2020 -0400
fc: Only do filtering by format once
The fontconfig configuration changes rarely, so we can avoid
unnecessary work by only doing the filtering by supported formats
once, and keeping the result.
pango/pangofc-fontmap.c | 81 +++++++++++++++++++++++++++++++++++--------------
1 file changed, 58 insertions(+), 23 deletions(-)
---
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index 4c2aa094..b3b6a53e 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -157,6 +157,7 @@ struct _PangoFcFontMapPrivate
guint closed : 1;
FcConfig *config;
+ FcFontSet *fonts;
};
struct _PangoFcFontFaceData
@@ -837,18 +838,29 @@ pango_fc_is_supported_font_format (FcPattern* pattern)
return FALSE;
}
+static FcFontSet *pango_fc_font_map_get_config_fonts (PangoFcFontMap *fcfontmap);
+
static FcFontSet *
-filter_fontset_by_format (FcFontSet *fontset)
+filter_by_format (FcFontSet **sets, int nsets)
{
FcFontSet *result;
- int i;
+ int set;
result = FcFontSetCreate ();
- for (i = 0; i < fontset->nfont; i++)
+ for (set = 0; set < nsets; set++)
{
- if (pango_fc_is_supported_font_format (fontset->fonts[i]))
+ FcFontSet *fontset = sets[set];
+ int i;
+
+ if (!fontset)
+ continue;
+
+ for (i = 0; i < fontset->nfont; i++)
{
+ if (!pango_fc_is_supported_font_format (fontset->fonts[i]))
+ continue;
+
FcPatternReference (fontset->fonts[i]);
FcFontSetAdd (result, fontset->fonts[i]);
}
@@ -863,34 +875,38 @@ pango_fc_patterns_get_font_pattern (PangoFcPatterns *pats, int i, gboolean *prep
if (i == 0)
{
FcResult result;
+
if (!pats->match && !pats->fontset)
- pats->match = FcFontMatch (pats->fontmap->priv->config, pats->pattern, &result);
+ {
+ FcFontSet *fonts;
- if (pats->match && pango_fc_is_supported_font_format (pats->match))
- {
- *prepare = FALSE;
- return pats->match;
- }
- }
+ fonts = pango_fc_font_map_get_config_fonts (pats->fontmap);
- if (!pats->fontset)
- {
- FcResult result;
- FcFontSet *filtered[2] = { NULL, };
- int i, n = 0;
+ pats->match = FcFontSetMatch (pats->fontmap->priv->config,
+ &fonts, 1,
+ pats->pattern,
+ &result);
+ }
- for (i = 0; i < 2; i++)
+ if (pats->match)
{
- FcFontSet *fonts = FcConfigGetFonts (pats->fontmap->priv->config, i);
- if (fonts)
- filtered[n++] = filter_fontset_by_format (fonts);
+ *prepare = FALSE;
+ return pats->match;
}
+ }
- pats->fontset = FcFontSetSort (pats->fontmap->priv->config, filtered, n, pats->pattern, FcTrue, NULL,
&result);
+ if (!pats->fontset)
+ {
+ FcResult result;
+ FcFontSet *fonts;
- for (i = 0; i < n; i++)
- FcFontSetDestroy (filtered[i]);
+ fonts = pango_fc_font_map_get_config_fonts (pats->fontmap);
+ pats->fontset = FcFontSetSort (pats->fontmap->priv->config,
+ &fonts, 1,
+ pats->pattern,
+ FcTrue, NULL,
+ &result);
if (pats->match)
{
@@ -1214,6 +1230,8 @@ pango_fc_font_map_fini (PangoFcFontMap *fcfontmap)
PangoFcFontMapPrivate *priv = fcfontmap->priv;
int i;
+ g_clear_pointer (&priv->fonts, FcFontSetDestroy);
+
g_queue_free (priv->fontset_cache);
priv->fontset_cache = NULL;
@@ -2065,6 +2083,8 @@ pango_fc_font_map_set_config (PangoFcFontMap *fcfontmap,
fcfontmap->priv->config = fcconfig;
+ g_clear_pointer (&fcfontmap->priv->fonts, FcFontSetDestroy);
+
if (oldconfig != fcconfig)
pango_fc_font_map_config_changed (fcfontmap);
@@ -2093,6 +2113,21 @@ pango_fc_font_map_get_config (PangoFcFontMap *fcfontmap)
return fcfontmap->priv->config;
}
+static FcFontSet *
+pango_fc_font_map_get_config_fonts (PangoFcFontMap *fcfontmap)
+{
+ if (fcfontmap->priv->fonts == NULL)
+ {
+ FcFontSet *sets[2];
+
+ sets[0] = FcConfigGetFonts (fcfontmap->priv->config, 0);
+ sets[1] = FcConfigGetFonts (fcfontmap->priv->config, 1);
+ fcfontmap->priv->fonts = filter_by_format (sets, 2);
+ }
+
+ return fcfontmap->priv->fonts;
+}
+
static PangoFcFontFaceData *
pango_fc_font_map_get_font_face_data (PangoFcFontMap *fcfontmap,
FcPattern *font_pattern)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]