mirror of
https://github.com/mintycube/dmenu.git
synced 2024-10-22 12:05:48 +00:00
inputw: improve correctness and startup performance
a massive amount of time inside readstdin() is spent trying to get the max input width and then put it into inputw, only for it to get clamped down to mw/3 inside setup(). it makes more sense to calculate inputw inside setup() once we have mw available. similar to the last patch, i see noticeable startup performance improvement: before -> after 160ms -> 60ms additionally this will take fallback fonts into account compared to the previous version, so it's not only more performant but also more correct. ref. https://git.suckless.org/dmenu/commit/77526f756e23e362081ac807521f901f2e5cd5e6.html Disclaimer: this may break the JSON patch
This commit is contained in:
parent
067aa41ac3
commit
761bc7939f
32
dmenu.c
32
dmenu.c
@ -1358,12 +1358,10 @@ readstdin(void)
|
|||||||
char buf[sizeof text], *p;
|
char buf[sizeof text], *p;
|
||||||
#if JSON_PATCH
|
#if JSON_PATCH
|
||||||
size_t i;
|
size_t i;
|
||||||
unsigned int imax = 0;
|
|
||||||
struct item *item;
|
struct item *item;
|
||||||
#else
|
#else
|
||||||
size_t i, imax = 0, size = 0;
|
size_t i, size = 0;
|
||||||
#endif // JSON_PATCH
|
#endif // JSON_PATCH
|
||||||
unsigned int tmpmax = 0;
|
|
||||||
|
|
||||||
#if PASSWORD_PATCH
|
#if PASSWORD_PATCH
|
||||||
if (passwd) {
|
if (passwd) {
|
||||||
@ -1415,19 +1413,6 @@ readstdin(void)
|
|||||||
#if HIGHPRIORITY_PATCH
|
#if HIGHPRIORITY_PATCH
|
||||||
items[i].hp = arrayhas(hpitems, hplength, items[i].text);
|
items[i].hp = arrayhas(hpitems, hplength, items[i].text);
|
||||||
#endif // HIGHPRIORITY_PATCH
|
#endif // HIGHPRIORITY_PATCH
|
||||||
#if PANGO_PATCH
|
|
||||||
drw_font_getexts(drw->font, buf, strlen(buf), &tmpmax, NULL, True);
|
|
||||||
#else
|
|
||||||
drw_font_getexts(drw->fonts, buf, strlen(buf), &tmpmax, NULL);
|
|
||||||
#endif // PANGO_PATCH
|
|
||||||
if (tmpmax > inputw) {
|
|
||||||
inputw = tmpmax;
|
|
||||||
#if JSON_PATCH
|
|
||||||
imax = items_ln - 1;
|
|
||||||
#else
|
|
||||||
imax = i;
|
|
||||||
#endif // JSON_PATCH
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (items)
|
if (items)
|
||||||
#if JSON_PATCH
|
#if JSON_PATCH
|
||||||
@ -1435,11 +1420,6 @@ readstdin(void)
|
|||||||
#else
|
#else
|
||||||
items[i].text = NULL;
|
items[i].text = NULL;
|
||||||
#endif // JSON_PATCH
|
#endif // JSON_PATCH
|
||||||
#if PANGO_PATCH
|
|
||||||
inputw = items ? TEXTWM(items[imax].text) : 0;
|
|
||||||
#else
|
|
||||||
inputw = items ? TEXTW(items[imax].text) : 0;
|
|
||||||
#endif // PANGO_PATCH
|
|
||||||
#if JSON_PATCH
|
#if JSON_PATCH
|
||||||
lines = MIN(lines, items_ln);
|
lines = MIN(lines, items_ln);
|
||||||
#else
|
#else
|
||||||
@ -1514,12 +1494,13 @@ static void
|
|||||||
setup(void)
|
setup(void)
|
||||||
{
|
{
|
||||||
int x, y, i, j;
|
int x, y, i, j;
|
||||||
unsigned int du;
|
unsigned int du, tmp;
|
||||||
XSetWindowAttributes swa;
|
XSetWindowAttributes swa;
|
||||||
XIM xim;
|
XIM xim;
|
||||||
Window w, dw, *dws;
|
Window w, dw, *dws;
|
||||||
XWindowAttributes wa;
|
XWindowAttributes wa;
|
||||||
XClassHint ch = {"dmenu", "dmenu"};
|
XClassHint ch = {"dmenu", "dmenu"};
|
||||||
|
struct item *item;
|
||||||
#ifdef XINERAMA
|
#ifdef XINERAMA
|
||||||
XineramaScreenInfo *info;
|
XineramaScreenInfo *info;
|
||||||
Window pw;
|
Window pw;
|
||||||
@ -1656,7 +1637,12 @@ setup(void)
|
|||||||
promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
|
promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
|
||||||
#endif // PANGO_PATCH
|
#endif // PANGO_PATCH
|
||||||
#endif // CENTER_PATCH
|
#endif // CENTER_PATCH
|
||||||
inputw = MIN(inputw, mw/3);
|
for (item = items; item && item->text; ++item) {
|
||||||
|
if ((tmp = textw_clamp(item->text, mw/3)) > inputw) {
|
||||||
|
if ((inputw = tmp) == mw/3)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
match();
|
match();
|
||||||
|
|
||||||
/* create menu window */
|
/* create menu window */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user