From 882101369388e59667744ec2fedbdc0179c4e35b Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Wed, 21 Aug 2013 19:34:55 -0700 Subject: fix find_font() performance --- st.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/st.c b/st.c index 7404c29..6e365f4 100644 --- a/st.c +++ b/st.c @@ -49,6 +49,7 @@ struct st_font { struct st_fontcache { XftFont *font; + unsigned c; enum { FRC_NORMAL, FRC_ITALIC, @@ -368,9 +369,8 @@ static XftColor *reverse_color(struct st_window *xw, XftColor *color, } } -static XftFont *find_font(struct st_window *xw, - struct st_font *font, - long u8char, unsigned flags) +static XftFont *find_font(struct st_window *xw, struct st_font *font, + unsigned flags, long u8char) { FcFontSet *fcsets[] = { font->set }; FcPattern *fcpattern, *fontpattern; @@ -383,8 +383,7 @@ static XftFont *find_font(struct st_window *xw, for (fc = xw->fontcache; fc < xw->fontcache + ARRAY_SIZE(xw->fontcache) && fc->font; fc++) - if (fc->flags == flags && - XftCharIndex(xw->dpy, fc->font, u8char)) + if (fc->flags == flags && fc->c == u8char) return fc->font; /* @@ -407,19 +406,17 @@ static XftFont *find_font(struct st_window *xw, xfont = XftFontOpenPattern(xw->dpy, fontpattern); - if (xfont) { - fc = &xw->fontcache[ARRAY_SIZE(xw->fontcache) - 1]; - if (fc->font) - XftFontClose(xw->dpy, fc->font); + fc = &xw->fontcache[ARRAY_SIZE(xw->fontcache) - 1]; + if (fc->font) + XftFontClose(xw->dpy, fc->font); - fc = xw->fontcache; + fc = xw->fontcache; + memmove(fc + 1, fc, + (ARRAY_SIZE(xw->fontcache) - 1) * sizeof(*fc)); - memmove(fc + 1, fc, - (ARRAY_SIZE(xw->fontcache) - 1) * sizeof(*fc)); - - fc->flags = flags; - fc->font = xfont; - } + fc->font = xfont; + fc->c = u8char; + fc->flags = flags; FcCharSetDestroy(fccharset); FcPatternDestroy(fcpattern); -- cgit v1.2.3