diff options
author | Kjartan Maraas <kmaraas@gnome.org> | 2005-09-16 20:14:29 +0000 |
---|---|---|
committer | Kjartan Maraas <kmaraas@src.gnome.org> | 2005-09-16 20:14:29 +0000 |
commit | 7768de1457224fcb168f0cf9f1622a633dd0e5cb (patch) | |
tree | 97bcbedf46ab1edd7b0fa0dbd3ad3f76d5f04d18 /src/vtexft.c | |
parent | 659f4c735aaea14d2ee44614677759c884800cd1 (diff) |
Optimize memory usage by releasing fonts that aren't needed early. Patch
2005-09-16 Kjartan Maraas <kmaraas@gnome.org>
* src/vtexft.c: (_vte_xft_font_for_char): Optimize memory
usage by releasing fonts that aren't needed early. Patch
from Mike Hearn. Closes bug #309322.
Diffstat (limited to 'src/vtexft.c')
-rw-r--r-- | src/vtexft.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/vtexft.c b/src/vtexft.c index 1995568..5321e4f 100644 --- a/src/vtexft.c +++ b/src/vtexft.c @@ -241,15 +241,25 @@ _vte_xft_font_for_char(struct _vte_xft_font *font, gunichar c) for (i = font->fonts->len; i < font->patterns->len; i++) { patternp = &g_array_index(font->patterns, FcPattern *, i); ftfont = XftFontOpenPattern(display, *patternp); + /* If the font was opened, it owns the pattern. */ if (ftfont != NULL) { *patternp = NULL; - } - g_array_append_val(font->fonts, ftfont); - if ((ftfont != NULL) && - (_vte_xft_char_exists(font, ftfont, c))) { - break; - } + + if (_vte_xft_char_exists(font, ftfont, c)) { + g_array_append_val(font->fonts, ftfont); + break; + } + + /* To save memory, close fonts that don't match the pattern */ + XftFontClose(display, ftfont); + ftfont = NULL; + } + + /* The patterns array must match up with the fonts array, even if + * that means appending a NULL to it. + */ + g_array_append_val(font->fonts, ftfont); } /* No match? */ |