From: | Andres Freund <andres(at)anarazel(dot)de> |
---|---|
To: | John Naylor <john(dot)naylor(at)enterprisedb(dot)com> |
Cc: | Jelte Fennema <Jelte(dot)Fennema(at)microsoft(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net> |
Subject: | Re: [PATCH] Optimize json_lex_string by batching character copying |
Date: | 2022-07-06 05:18:01 |
Message-ID: | 20220706051801.gfbzjxgflbsglyt6@awork3.anarazel.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi,
On 2022-07-06 12:10:20 +0700, John Naylor wrote:
> diff --git a/src/common/jsonapi.c b/src/common/jsonapi.c
> index eeedc0645a..ad4858c623 100644
> --- a/src/common/jsonapi.c
> +++ b/src/common/jsonapi.c
> @@ -851,10 +851,26 @@ json_lex_string(JsonLexContext *lex)
> }
> else if (lex->strval != NULL)
> {
> + /* start lookahead at next byte */
> + char *p = s + 1;
> +
> if (hi_surrogate != -1)
> return JSON_UNICODE_LOW_SURROGATE;
>
> - appendStringInfoChar(lex->strval, *s);
> + while (p < end)
> + {
> + if (*p == '\\' || *p == '"' || (unsigned char) *p < 32)
> + break;
> + p++;
> + }
> +
> + appendBinaryStringInfo(lex->strval, s, p - s);
> +
> + /*
> + * s will be incremented at the top of the loop, so set it to just
> + * behind our lookahead position
> + */
> + s = p - 1;
> }
> }
>
> --
> 2.36.1
I think before committing something along those lines we should make the
relevant bits also be applicable when ->strval is NULL, as several functions
use that (notably json_in IIRC). Afaics we'd just need to move the strval
check to be around the appendBinaryStringInfo(). And it should simplify the
function, because some of the relevant code is duplicated outside as well...
Greetings,
Andres Freund
From | Date | Subject | |
---|---|---|---|
Next Message | Andres Freund | 2022-07-06 05:28:11 | Re: AIX support - alignment issues |
Previous Message | John Naylor | 2022-07-06 05:10:20 | Re: [PATCH] Optimize json_lex_string by batching character copying |