summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas E. Dickey <dickey@invisible-island.net>2022-07-04 07:41:12 -0400
committerThomas E. Dickey <dickey@invisible-island.net>2022-07-06 04:27:57 -0400
commit318c6984baba0ea02147dc72a97e331234b6baf7 (patch)
tree1531ff18701ce7491afdcc84deefe2d0b2f3e1f3
parent33c1e1e3a5c08b690e145cc193d52fc13869af7b (diff)
downloadxorg-lib-libXft-318c6984baba0ea02147dc72a97e331234b6baf7.tar.gz
refactor _XftFontUncacheGlyph, separate the two types of loop for readability
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
-rw-r--r--src/xftglyphs.c54
1 files changed, 35 insertions, 19 deletions
diff --git a/src/xftglyphs.c b/src/xftglyphs.c
index 7e238b3..6edcf22 100644
--- a/src/xftglyphs.c
+++ b/src/xftglyphs.c
@@ -838,6 +838,9 @@ XftFontUnloadGlyphs (Display *dpy,
continue;
if (xftg->glyph_memory)
{
+ if (XftDebug() & XFT_DBG_CACHEV)
+ printf ("Uncaching glyph 0x%x size %ld\n",
+ glyphindex, xftg->glyph_memory);
if (font->format)
{
if (font->glyphset)
@@ -1004,7 +1007,7 @@ XftCharIndex (Display *dpy,
}
/*
- * Pick a random glyph from the font and remove it from the cache
+ * Remove glyph(s) from the font to reduce memory-usage.
*/
_X_HIDDEN void
_XftFontUncacheGlyph (Display *dpy, XftFont *pub)
@@ -1016,40 +1019,53 @@ _XftFontUncacheGlyph (Display *dpy, XftFont *pub)
if (!font->glyph_memory)
return;
+
+ if (XftDebug() & XFT_DBG_CACHE)
+ _XftFontValidateMemory (dpy, pub);
+
if (font->use_free_glyphs)
{
+ /*
+ * Pick a random glyph from the font and remove it from the cache
+ */
glyph_memory = ((unsigned long)rand() % font->glyph_memory);
+ for (glyphindex = 0; glyphindex < font->num_glyphs; glyphindex++)
+ {
+ xftg = font->glyphs[glyphindex];
+ if (xftg)
+ {
+ if (xftg->glyph_memory > glyph_memory)
+ {
+ XftFontUnloadGlyphs (dpy, pub, &glyphindex, 1);
+ break;
+ }
+ glyph_memory -= xftg->glyph_memory;
+ }
+ }
}
else
{
+ /*
+ * Free all glyphs, since they are part of a set.
+ */
if (font->glyphset)
{
XRenderFreeGlyphSet (dpy, font->glyphset);
font->glyphset = 0;
}
- glyph_memory = 0;
- }
-
- if (XftDebug() & XFT_DBG_CACHE)
- _XftFontValidateMemory (dpy, pub);
- for (glyphindex = 0; glyphindex < font->num_glyphs; glyphindex++)
- {
- xftg = font->glyphs[glyphindex];
- if (xftg)
+ for (glyphindex = 0; glyphindex < font->num_glyphs; glyphindex++)
{
- if (xftg->glyph_memory > glyph_memory)
+ xftg = font->glyphs[glyphindex];
+ if (xftg)
{
- if (XftDebug() & XFT_DBG_CACHEV)
- printf ("Uncaching glyph 0x%x size %ld\n",
- glyphindex, xftg->glyph_memory);
- XftFontUnloadGlyphs (dpy, pub, &glyphindex, 1);
- if (!font->use_free_glyphs)
- continue;
- break;
+ if (xftg->glyph_memory > 0)
+ {
+ XftFontUnloadGlyphs (dpy, pub, &glyphindex, 1);
+ }
}
- glyph_memory -= xftg->glyph_memory;
}
}
+
if (XftDebug() & XFT_DBG_CACHE)
_XftFontValidateMemory (dpy, pub);
}