From owner-freebsd-hackers Mon Jul 30 9: 4:53 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from mail.wrs.com (unknown-1-11.windriver.com [147.11.1.11]) by hub.freebsd.org (Postfix) with ESMTP id 06F1837B401; Mon, 30 Jul 2001 09:04:47 -0700 (PDT) (envelope-from jhb@FreeBSD.org) Received: from laptop.baldwin.cx (john@[147.11.46.217]) by mail.wrs.com (8.9.3/8.9.1) with ESMTP id JAA16831; Mon, 30 Jul 2001 09:04:46 -0700 (PDT) Message-ID: X-Mailer: XFMail 1.4.0 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: <20010727214412.A91434@dragon.nuxi.com> Date: Mon, 30 Jul 2001 09:04:47 -0700 (PDT) From: John Baldwin To: "David O'Brien" Subject: RE: [PATCH] reduce text(code) size and improve clarity of pkg_ad Cc: freebsd-hackers@FreeBSD.org Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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 -- 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