Re: [dwm] [patch] simplification to drawtext

From: Anselm R. Garbe <arg_AT_suckless.org>
Date: Mon, 2 Jun 2008 11:00:29 +0200

On Mon, Jun 02, 2008 at 10:16:34AM +0200, Premysl Hruby wrote:
> On (02/06/08 09:56), Enno Gottox Boland wrote:
> > To: dynamic window manager <dwm_AT_suckless.org>
> > From: Enno Gottox Boland <gottox_AT_gmail.com>
> > Subject: Re: [dwm] [patch] simplification to drawtext
> > Reply-To: dynamic window manager <dwm_AT_suckless.org>
> > List-Id: dynamic window manager <dwm.suckless.org>
> >
> > whoops...
> >
> > memcpy(&buf[MAX(0, len - 3)], "...", MIN(3, len));
> >
>
> Still, this is not needed, as buf is ALWAYS greater than 3 bytes. So:
>
> memcpy(&buf[MAX(0, len - 3)], "...", 3);
>
> is sufficent, this was my thought when I wrote this memcpy variant.

Yes, I came to the same conclusion yesterday. Even if len < 3 it
doesn't matter, because MAX(0, len - 3) will always evaluate to
0 for len <= 3 and sizeof buf > 3 is a precondition.

However memcpy() might be slower than the following replacement:

        if(len < olen)
                for(i = len; i >= MAX(0, len - 3); buf[i--] = '.');

memcpy is an additional function call -- the for-solution might
not be the fastest because a sane memcpy will attempt to copy
4xlong resp. 1 long in a step for speed reasons, however for the
3 dots this speed hack won't be used anyways.

Kind regards,

-- 
 Anselm R. Garbe >< http://www.suckless.org/ >< GPG key: 0D73F361
Received on Mon Jun 02 2008 - 11:00:30 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:46:49 UTC