Skip site navigation (1) Skip section navigation (2)

Re: Faster StrNCpy

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Martijn van Oosterhout <kleptog(at)svana(dot)org>, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: Faster StrNCpy
Date: 2006-09-26 21:04:14
Message-ID: 29846.1159304654@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-patches
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?

			regards, tom lane

In response to

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2006-09-26 21:12:25
Subject: Re: Faster StrNCpy
Previous:From: Neil ConwayDate: 2006-09-26 21:03:50
Subject: Re: Faster StrNCpy

pgsql-patches by date

Next:From: Tom LaneDate: 2006-09-26 21:12:25
Subject: Re: Faster StrNCpy
Previous:From: Neil ConwayDate: 2006-09-26 21:03:50
Subject: Re: Faster StrNCpy

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group