Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 30 Jul 2001 09:04:47 -0700 (PDT)
From:      John Baldwin <jhb@FreeBSD.org>
To:        "David O'Brien" <obrien@FreeBSD.org>
Cc:        freebsd-hackers@FreeBSD.org
Subject:   RE: [PATCH] reduce text(code) size and improve clarity of pkg_ad
Message-ID:  <XFMail.010730090447.jhb@FreeBSD.org>
In-Reply-To: <20010727214412.A91434@dragon.nuxi.com>

next in thread | previous in thread | raw e-mail | index | archive | help

On 28-Jul-01 David O'Brien wrote:
> I'd like to apply this patch to pkg_add which reduces the amount of code
> the compiler generates, and improves the clarity of the code.
> 
> 1. s_strl* is obvious some form of "safe" strl{cpy,cat}.  But *WHAT*
>    does it make "safe"?  Isn't obvious w/o having to track down the
>    s_strl{cat,cpy} function definitions.
> 
> 2. The current code has more function call overhead than is needed.  And
>    it reduces the size of the basic block for the optimizer to work on.
>    It also potentially has cache miss penalties.

static __inline int
s_strlcpy(char *dst, const char *src, size_t size)
{
     return (strlcpy(dst, src, size) >= size);
}

and the same for s_strlcat() is a much shorter patch :) while still being
slightly more readable.  Not to mention your patch broke one case by using
'>' instead of '>=' for the test, while just making the functions inline
wouldn't have this problem. :)

> -         if (s_strlcpy(FirstPen, optarg, sizeof(FirstPen)))
> +         if (strlcpy(FirstPen, optarg, sizeof(FirstPen)) > sizeof(FirstPen))

Should be >=.

-- 

John Baldwin <jhb@FreeBSD.org> -- http://www.FreeBSD.org/~jhb/
PGP Key: http://www.baldwin.cx/~john/pgpkey.asc
"Power Users Use the Power to Serve!"  -  http://www.FreeBSD.org/

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.010730090447.jhb>