summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kmo@daterainc.com>2013-08-21 19:34:55 -0700
committerKent Overstreet <kmo@daterainc.com>2013-08-21 19:34:55 -0700
commit882101369388e59667744ec2fedbdc0179c4e35b (patch)
tree06ffc7b8b0bc536234e013f4bbfea8dfd2548940
parent6417ce01971e4c5213ecf813aebce73095ea466d (diff)
fix find_font() performance
-rw-r--r--st.c29
1 files 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);