Re: [PATCH] avoid double scanning in function byteain

Поиск
Список
Период
Сортировка
От Kirill Reshke
Тема Re: [PATCH] avoid double scanning in function byteain
Дата
Msg-id CALdSSPiov_2HrvLxHEUYD=LpJ6oetQ_-9=D77+j2Spi3TEgepw@mail.gmail.com
обсуждение исходный текст
Ответ на [PATCH] avoid double scanning in function byteain  (Steven Niu <niushiji@gmail.com>)
Ответы Re: [PATCH] avoid double scanning in function byteain
Список pgsql-hackers
On Wed, 26 Mar 2025 at 12:17, Steven Niu <niushiji@gmail.com> wrote:
>
> Hi,

Hi!

> This double scanning can be inefficient, especially for large inputs.
> So I optimized the function to eliminate the need for two scans,
> while preserving correctness and efficiency.

While the argument that processing input once not twice is fast is
generally true, may we have some simple bench here just to have an
idea how valuable this patch is?


Patch:


>+ /* Handle traditional escaped style in a single pass */
>+ input_len = strlen(inputText);
>+ result = palloc(input_len + VARHDRSZ);  /* Allocate max possible size */
>  rp = VARDATA(result);
>+ tp = inputText;
>+
>  while (*tp != '\0')


Isn't this `strlen` O(n) + `while` O(n)? Where is the speed up?



[0] https://github.com/bminor/glibc/blob/master/string/strlen.c#L43-L45

-- 
Best regards,
Kirill Reshke



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