Re: Faster StrNCpy

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, Martijn van Oosterhout <kleptog(at)svana(dot)org>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Faster StrNCpy
Date: 2006-10-03 00:01:25
Message-ID: 200610030001.k9301Pn20897@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> Alvaro Herrera <alvherre(at)commandprompt(dot)com> writes:
> > You'll notice that it iterates once per char. Between that and the
> > strlen() call in Tom's version, not sure which is the lesser evil.
>
> Yeah, I was wondering that too. My code would require two scans of the
> source string (one inside strlen and one in memcpy), but in much of our
> usage the source and dest should be reasonably well aligned and one
> could expect memcpy to be using word rather than byte operations, so you
> might possibly make it back on the strength of fewer write cycles. And
> on the third hand, for short source strings none of this matters and
> the extra function call involved for strlen/memcpy probably dominates.
>
> I'm happy to just use the OpenBSD version as a src/port module.
> Any objections?

I found this URL about the function history of strlcpy():

http://www.gratisoft.us/todd/papers/strlcpy.html

I added the URL to port/strlcpy.c.

--
Bruce Momjian bruce(at)momjian(dot)us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Josh Berkus 2006-10-03 00:02:45 Re: Faster StrNCpy
Previous Message Bruce Momjian 2006-10-03 00:00:25 Re: Sane error messages for SSL retry cases

Browse pgsql-patches by date

  From Date Subject
Next Message Josh Berkus 2006-10-03 00:02:45 Re: Faster StrNCpy
Previous Message Guillaume Lelarge 2006-10-02 23:36:50 Small documentation patch