Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3de359f

Browse files
committed
Simplify json lexing state
Instead of updating the length as we go, use a const pointer to end ofthe input, which we know already at the start.This simplifies the coding and may improve performance slightly, butthe real motivation for doing this is to make further changes in thisarea easier to reason about.Discussion:https://www.postgresql.org/message-id/CAFBsxsGhaR2KQ5eisaK%3D6Vm60t%3DaxhD8Ckj1qFoCH1pktZi%2B2w%40mail.gmail.com
1 parent3140f08 commit3de359f

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

‎src/common/jsonapi.c‎

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -519,26 +519,23 @@ JsonParseErrorType
519519
json_lex(JsonLexContext*lex)
520520
{
521521
char*s;
522-
intlen;
522+
char*constend=lex->input+lex->input_length;
523523
JsonParseErrorTyperesult;
524524

525525
/* Skip leading whitespace. */
526526
s=lex->token_terminator;
527-
len=s-lex->input;
528-
while (len<lex->input_length&&
529-
(*s==' '||*s=='\t'||*s=='\n'||*s=='\r'))
527+
while (s<end&& (*s==' '||*s=='\t'||*s=='\n'||*s=='\r'))
530528
{
531529
if (*s++=='\n')
532530
{
533531
++lex->line_number;
534532
lex->line_start=s;
535533
}
536-
len++;
537534
}
538535
lex->token_start=s;
539536

540537
/* Determine token type. */
541-
if (len >=lex->input_length)
538+
if (s >=end)
542539
{
543540
lex->token_start=NULL;
544541
lex->prev_token_terminator=lex->token_terminator;
@@ -623,7 +620,7 @@ json_lex(JsonLexContext *lex)
623620
* the whole word as an unexpected token, rather than just
624621
* some unintuitive prefix thereof.
625622
*/
626-
for (p=s;p-s<lex->input_length-len&&JSON_ALPHANUMERIC_CHAR(*p);p++)
623+
for (p=s;p<end&&JSON_ALPHANUMERIC_CHAR(*p);p++)
627624
/* skip */ ;
628625

629626
/*
@@ -672,21 +669,19 @@ static inline JsonParseErrorType
672669
json_lex_string(JsonLexContext*lex)
673670
{
674671
char*s;
675-
intlen;
672+
char*constend=lex->input+lex->input_length;
676673
inthi_surrogate=-1;
677674

678675
if (lex->strval!=NULL)
679676
resetStringInfo(lex->strval);
680677

681678
Assert(lex->input_length>0);
682679
s=lex->token_start;
683-
len=lex->token_start-lex->input;
684680
for (;;)
685681
{
686682
s++;
687-
len++;
688683
/* Premature end of the string. */
689-
if (len >=lex->input_length)
684+
if (s >=end)
690685
{
691686
lex->token_terminator=s;
692687
returnJSON_INVALID_TOKEN;
@@ -704,8 +699,7 @@ json_lex_string(JsonLexContext *lex)
704699
{
705700
/* OK, we have an escape character. */
706701
s++;
707-
len++;
708-
if (len >=lex->input_length)
702+
if (s >=end)
709703
{
710704
lex->token_terminator=s;
711705
returnJSON_INVALID_TOKEN;
@@ -718,8 +712,7 @@ json_lex_string(JsonLexContext *lex)
718712
for (i=1;i <=4;i++)
719713
{
720714
s++;
721-
len++;
722-
if (len >=lex->input_length)
715+
if (s >=end)
723716
{
724717
lex->token_terminator=s;
725718
returnJSON_INVALID_TOKEN;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp