From: | Greg Stark <gsstark(at)mit(dot)edu> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: [PATCH] Custom code int(32|64) => text conversions out of performance reasons |
Date: | 2010-11-20 20:11:43 |
Message-ID: | AANLkTi=DwmNiKW7SWYoz3ZZ6H8K0Bu9COi8DoZKL3XnQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Sat, Nov 20, 2010 at 6:31 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Robert Haas <robertmhaas(at)gmail(dot)com> writes:
>> On Sat, Nov 20, 2010 at 12:34 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>> what about building it working backwards from the end of the buffer
>>> and then memmove'ing it down to the start of the buffer?
>
>> I think that might be more clever than is really warranted. I get
>> your point about buffer overrun, but I don't think it's that hard for
>> callers to do the right thing, so I'm inclined to think that's not
>> worth much in this case.
It also seems wrong that a caller might happen to know that their
argument will never be more than n digits but still has to allocate a
buffer large enough to hold 2^64.
>
> Fair enough --- it was just a passing thought.
>
>> I had given some thought to whether it might make sense to try to
>> figure out how long the string will be before we actually start
>> generating it, so that we can just start in the exactly right space
>> and have to clean up afterward. But the obvious implementation seems
>> like it could be more expensive than just doing the copy.
>
> Yeah. You certainly don't want to do the division sequence twice,
> and a log() call wouldn't be cheap either, and there don't seem to
> be many other alternatives.
There are bittwiddling hacks for computing log based 2. I'm not sure
it's worth worrying about to this degree though.
--
greg
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2010-11-20 20:21:20 | Re: [PATCH] Custom code int(32|64) => text conversions out of performance reasons |
Previous Message | Andres Freund | 2010-11-20 19:47:20 | Re: [PATCH] Custom code int(32|64) => text conversions out of performance reasons |