Обсуждение: possible repalloc() in icu_convert_case()

Поиск
Список
Период
Сортировка

possible repalloc() in icu_convert_case()

От
Anton Voloshin
Дата:
Hello,

in src/backend/utils/adt/formatting.c, in icu_convert_case() I see:
     if (status == U_BUFFER_OVERFLOW_ERROR)
     {
         /* try again with adjusted length */
         pfree(*buff_dest);
         *buff_dest = palloc(len_dest * sizeof(**buff_dest));
         ...

Is there any reason why this should not be repalloc()?

In case it should be, I've attached a corresponding patch.

-- 
Anton Voloshin
Postgres Professional: https://www.postgrespro.com
Russian Postgres Company

Вложения

Re: possible repalloc() in icu_convert_case()

От
Tom Lane
Дата:
Anton Voloshin <a.voloshin@postgrespro.ru> writes:
> in src/backend/utils/adt/formatting.c, in icu_convert_case() I see:
>      if (status == U_BUFFER_OVERFLOW_ERROR)
>      {
>          /* try again with adjusted length */
>          pfree(*buff_dest);
>          *buff_dest = palloc(len_dest * sizeof(**buff_dest));
>          ...

> Is there any reason why this should not be repalloc()?

repalloc is likely to be more expensive, since it implies copying
data which isn't helpful here.  I think this code is fine as-is.

            regards, tom lane



Re: possible repalloc() in icu_convert_case()

От
Anton Voloshin
Дата:
On 04.04.2021 19:20, Tom Lane wrote:
> repalloc is likely to be more expensive, since it implies copying
> data which isn't helpful here.  I think this code is fine as-is.

Oh, you are right, thanks. I did not think properly about copying in 
repalloc.

-- 
Anton Voloshin
Postgres Professional: https://www.postgrespro.com
Russian Postgres Company