summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas E. Dickey <dickey@invisible-island.net>2022-07-04 20:08:58 -0400
committerThomas E. Dickey <dickey@invisible-island.net>2022-07-06 04:28:30 -0400
commit36a8474813aba2be263f9de88ad9adfe85c0daf1 (patch)
treea01a0d88b35692e872c6e1faeb1afb586e6b7e87
parent01d44d70e9bd770ac365c88e09c5e432d2e517ad (diff)
downloadxorg-lib-libXft-36a8474813aba2be263f9de88ad9adfe85c0daf1.tar.gz
improve glyph management by relinking to unload least-recently used glyphs
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
-rw-r--r--src/xftglyphs.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/xftglyphs.c b/src/xftglyphs.c
index 076acc5..10ab45e 100644
--- a/src/xftglyphs.c
+++ b/src/xftglyphs.c
@@ -957,8 +957,40 @@ XftFontCheckGlyph (Display *dpy,
*nmissing = n;
return FcTrue;
}
- else
- return FcFalse;
+
+ /*
+ * Make unloading faster by moving newly-referenced glyphs to the front
+ * of the list, leaving the less-used glyphs on the end.
+ */
+ if (font->track_mem_usage
+ && font->total_inuse > 10
+ && font->newest != FT_UINT_MAX
+ && font->newest != glyph)
+ {
+ XftGlyphUsage *xuse = (XftGlyphUsage *) xftg;
+ XftGlyphUsage *xtmp = (XftGlyphUsage *) font->glyphs[font->newest];
+ XftGlyphUsage *xold;
+ XftGlyphUsage *xnew;
+
+ /* delink */
+ xold = (XftGlyphUsage *) font->glyphs[xuse->older];
+ xnew = (XftGlyphUsage *) font->glyphs[xuse->newer];
+ assert(xold != NULL);
+ assert(xnew != NULL);
+ xold->newer = xuse->newer;
+ xnew->older = xuse->older;
+
+ /* relink */
+ xnew = (XftGlyphUsage *) font->glyphs[xtmp->newer];
+ assert(xnew != NULL);
+ xnew->older = glyph;
+ xuse->older = font->newest;
+ xuse->newer = xtmp->newer;
+ xtmp->newer = glyph;
+
+ font->newest = glyph;
+ }
+ return FcFalse;
}
_X_EXPORT FcBool