Re: [HACKERS] strncmp->memcmp when we know the shorter length

2010-12-22 Thread Noah Misch
On Tue, Dec 21, 2010 at 10:15:41PM -0500, Robert Haas wrote: > A little benchmarking reveals that on my system (MacOS X 10.6.5) it > appears that strncmp() is faster for a 4 character string, but > memcmp() is faster for a 5+ character string. Good call; I hadn't considered that possibility. > So

Re: [HACKERS] strncmp->memcmp when we know the shorter length

2010-12-21 Thread Tom Lane
Robert Haas writes: > On Tue, Dec 21, 2010 at 10:24 PM, Tom Lane wrote: >> I'm fairly uncomfortable about the broad swath and low return of this >> patch.  Noah is assuming that none of these places are relying on >> strncmp to stop short upon finding a null, and I don't believe that >> that's a

Re: [HACKERS] strncmp->memcmp when we know the shorter length

2010-12-21 Thread Robert Haas
On Tue, Dec 21, 2010 at 10:24 PM, Tom Lane wrote: > Robert Haas writes: >> If it's done properly, I don't see how this would be a risk. > > I'm fairly uncomfortable about the broad swath and low return of this > patch.  Noah is assuming that none of these places are relying on > strncmp to stop s

Re: [HACKERS] strncmp->memcmp when we know the shorter length

2010-12-21 Thread Tom Lane
Robert Haas writes: > If it's done properly, I don't see how this would be a risk. I'm fairly uncomfortable about the broad swath and low return of this patch. Noah is assuming that none of these places are relying on strncmp to stop short upon finding a null, and I don't believe that that's a s

Re: [HACKERS] strncmp->memcmp when we know the shorter length

2010-12-21 Thread Robert Haas
On Tue, Dec 21, 2010 at 6:24 PM, Robert Haas wrote: > On Mon, Dec 20, 2010 at 1:10 PM, Noah Misch wrote: >> When the caller knows the smaller string length, memcmp and strncmp are >> functionally equivalent.  Since memcmp need not watch each byte for a NULL >> terminator, it often compares a CPU

Re: [HACKERS] strncmp->memcmp when we know the shorter length

2010-12-21 Thread Gurjeet Singh
On Tue, Dec 21, 2010 at 9:01 PM, Robert Haas wrote: > On Tue, Dec 21, 2010 at 8:29 PM, Gurjeet Singh > wrote: > > On Tue, Dec 21, 2010 at 6:24 PM, Robert Haas > wrote: > >> > >> On Mon, Dec 20, 2010 at 1:10 PM, Noah Misch wrote: > >> > When the caller knows the smaller string length, memcmp an

Re: [HACKERS] strncmp->memcmp when we know the shorter length

2010-12-21 Thread Robert Haas
On Tue, Dec 21, 2010 at 8:29 PM, Gurjeet Singh wrote: > On Tue, Dec 21, 2010 at 6:24 PM, Robert Haas wrote: >> >> On Mon, Dec 20, 2010 at 1:10 PM, Noah Misch wrote: >> > When the caller knows the smaller string length, memcmp and strncmp are >> > functionally equivalent.  Since memcmp need not w

Re: [HACKERS] strncmp->memcmp when we know the shorter length

2010-12-21 Thread Gurjeet Singh
On Tue, Dec 21, 2010 at 6:24 PM, Robert Haas wrote: > On Mon, Dec 20, 2010 at 1:10 PM, Noah Misch wrote: > > When the caller knows the smaller string length, memcmp and strncmp are > > functionally equivalent. Since memcmp need not watch each byte for a > NULL > > terminator, it often compares

Re: [HACKERS] strncmp->memcmp when we know the shorter length

2010-12-21 Thread Robert Haas
On Mon, Dec 20, 2010 at 1:10 PM, Noah Misch wrote: > When the caller knows the smaller string length, memcmp and strncmp are > functionally equivalent.  Since memcmp need not watch each byte for a NULL > terminator, it often compares a CPU word at a time for better performance.   > The > attached

[HACKERS] strncmp->memcmp when we know the shorter length

2010-12-20 Thread Noah Misch
When the caller knows the smaller string length, memcmp and strncmp are functionally equivalent. Since memcmp need not watch each byte for a NULL terminator, it often compares a CPU word at a time for better performance. The attached patch changes use of strncmp to memcmp where we have the length