Re: [hackers] Re: [dmenu][patch] Improve speed of drw_text when provided with large strings

From: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Mon, 9 Aug 2021 18:35:57 +0200

On Sat, Aug 07, 2021 at 09:39:44PM -0400, Miles Alan wrote:
> On Sat, Aug 7, 2021, at 9:34 PM, m_AT_milesalan.com wrote:
> > - for (len = MIN(utf8strlen, sizeof(buf) - 1); len && ew > w; len--)
> > - drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
> > + if (ew > w)
> > + for (ew = 0, len = 0; ew < w - lpad * 2 && len < MIN(utf8strlen,
> > sizeof(buf) - 1); len++)
> > + drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
> > + else
> > + len = MIN(utf8strlen, sizeof(buf) - 1);
>
> To test, try selecting previous/next items with the following (adjust -c as needed):
> for i in $(seq 20); do
> cat /dev/urandom | base64 | tr -d '\n' | head -c 1000000
> done | ./dmenu -l 10
>

Hi Miles,

Thanks for the patch. It uses indeed less resources for very long lines and it
makes more sense to do it this way.

A small change for the test script, you probably want to add a newline (echo)
between it:

        for i in $(seq 20); do
                cat /dev/urandom | base64 | tr -d '\n' | head -c 1000000
        echo
        done | ./dmenu -l 10

I synced the code to dwm and the libsl repository too.

-- 
Kind regards,
Hiltjo
Received on Mon Aug 09 2021 - 18:35:57 CEST

This archive was generated by hypermail 2.3.0 : Mon Aug 09 2021 - 18:36:36 CEST