Collin Funk <[email protected]> writes:

> Oops, I rewrote the patch to simplify it a bit. In the process I forgot
> to add the null terminator, since the line buffer doesn't do that for
> us. It would be something like this:
>
>       if (MB_CUR_MAX <= 1)
>         {
>           line->buf.buffer[line->buf.length - 1] = '\0';
>           do
>             {
>               char *start = ptr + strspn (ptr, "\n\t ");
>               char *end = start + strcspn (start, "\n\t ");
>               idx_t const len = end - start;
>               if (0 < len)
>                 extract_field (line, start, len);
>               ptr = end + (ptr < lim);
>             }
>           while (ptr < lim);
>           line->buf.buffer[line->buf.length - 1] = eolchar;
>         }

Also, noting here that the performance is terrible with many NUL bytes
since it will call strspn and strcspn each once per NUL. Perhaps next
release I'll have a look at adding memchr3 and doing it that way, which
would avoid this issue.

Collin

Reply via email to