Re: [PATCH] Custom code int(32|64) => text conversions out of performance reasons

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [PATCH] Custom code int(32|64) => text conversions out of performance reasons
Дата
Msg-id 27857.1290267512@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: [PATCH] Custom code int(32|64) => text conversions out of performance reasons  (Robert Haas <robertmhaas@gmail.com>)
Ответы Re: [PATCH] Custom code int(32|64) => text conversions out of performance reasons  (Robert Haas <robertmhaas@gmail.com>)
Список pgsql-hackers
Robert Haas <robertmhaas@gmail.com> writes:
> It occurs to me belatedly that there might be a better way to do this.
>  Instead of flipping value from negative to positive, with a special
> case for the smallest possible integer, we could do it the other
> round.  And actually, I think we can rid of neg, too.

The trouble with that approach is that you have to depend on the
direction of rounding for negative quotients.  Which was unspecified
before C99, and it's precisely pre-C99 compilers that are posing a
hazard to the current coding.

FWIW, I find the code still pretty darn unsightly.  I think this change
is just wrong:
    * Avoid problems with the most negative integer not being representable    * as a positive integer.    */
-   if (value == INT32_MIN)
+   if (value == INT_MIN)   {       memcpy(a, "-2147483648", 12);

and even with INT32_MIN it was pretty silly, because there is exactly 0
hope of the code behaving sanely for some other value of the symbolic
constant.  I think it'd be much better to abandon the macros altogether
and write
   if (value == (-2147483647-1))   {       memcpy(a, "-2147483648", 12);

Likewise for the int64 case, which BTW is no safer for pre-C99 compilers
than it was yesterday: LL is not the portable way to write int64
constants.
        regards, tom lane


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Alexander Korotkov
Дата:
Сообщение: Re: Fix for seg picksplit function
Следующее
От: Robert Haas
Дата:
Сообщение: Re: [PATCH] Custom code int(32|64) => text conversions out of performance reasons