[pango/speed-up-format-filtering: 3/8] 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: 3/8] fc: Only do filtering by format once
- Date: Sat, 22 Aug 2020 01:27:01 +0000 (UTC)
commit e72dc7eb89ffb78bad8086e2029b427af47cc0d9
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 | 77 +++++++++++++++++++++++++++++++++++++------------
1 file changed, 58 insertions(+), 19 deletions(-)
---
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index 4c2aa094..47c77f46 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -157,6 +157,7 @@ struct _PangoFcFontMapPrivate
guint closed : 1;
FcConfig *config;
+ FcFontSet *fonts[2];
};
struct _PangoFcFontFaceData
@@ -837,6 +838,9 @@ pango_fc_is_supported_font_format (FcPattern* pattern)
return FALSE;
}
+static FcFontSet **pango_fc_font_map_get_config_fonts (PangoFcFontMap *fcfontmap,
+ int *nsets);
+
static FcFontSet *
filter_fontset_by_format (FcFontSet *fontset)
{
@@ -863,34 +867,40 @@ 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 **sets;
+ int nsets;
- if (pats->match && pango_fc_is_supported_font_format (pats->match))
- {
- *prepare = FALSE;
- return pats->match;
- }
- }
+ sets = pango_fc_font_map_get_config_fonts (pats->fontmap, &nsets);
- if (!pats->fontset)
- {
- FcResult result;
- FcFontSet *filtered[2] = { NULL, };
- int i, n = 0;
+ pats->match = FcFontSetMatch (pats->fontmap->priv->config,
+ sets, nsets,
+ 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 **sets;
+ int nsets;
- for (i = 0; i < n; i++)
- FcFontSetDestroy (filtered[i]);
+ sets = pango_fc_font_map_get_config_fonts (pats->fontmap, &nsets);
+ pats->fontset = FcFontSetSort (pats->fontmap->priv->config,
+ sets, nsets,
+ pats->pattern,
+ FcTrue, NULL,
+ &result);
if (pats->match)
{
@@ -1214,6 +1224,9 @@ pango_fc_font_map_fini (PangoFcFontMap *fcfontmap)
PangoFcFontMapPrivate *priv = fcfontmap->priv;
int i;
+ for (i = 0; i < 2; i++)
+ g_clear_pointer (&priv->fonts[i], FcFontSetDestroy);
+
g_queue_free (priv->fontset_cache);
priv->fontset_cache = NULL;
@@ -2055,6 +2068,7 @@ pango_fc_font_map_set_config (PangoFcFontMap *fcfontmap,
FcConfig *fcconfig)
{
FcConfig *oldconfig;
+ int i;
g_return_if_fail (PANGO_IS_FC_FONT_MAP (fcfontmap));
@@ -2065,6 +2079,9 @@ pango_fc_font_map_set_config (PangoFcFontMap *fcfontmap,
fcfontmap->priv->config = fcconfig;
+ for (i = 0; i < 2; i++)
+ g_clear_pointer (&fcfontmap->priv->fonts[i], FcFontSetDestroy);
+
if (oldconfig != fcconfig)
pango_fc_font_map_config_changed (fcfontmap);
@@ -2093,6 +2110,28 @@ pango_fc_font_map_get_config (PangoFcFontMap *fcfontmap)
return fcfontmap->priv->config;
}
+static FcFontSet **
+pango_fc_font_map_get_config_fonts (PangoFcFontMap *fcfontmap,
+ int *nsets)
+{
+ if (fcfontmap->priv->fonts[0] == NULL &&
+ fcfontmap->priv->fonts[1] == NULL)
+ {
+ int set;
+
+ for (set = 0; set < 2; set++)
+ {
+ FcFontSet *fonts;
+
+ fonts = FcConfigGetFonts (fcfontmap->priv->config, set);
+ fcfontmap->priv->fonts[set] = filter_fontset_by_format (fonts);
+ }
+ }
+
+ *nsets = 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]