Skip to content

Commit f5be0e5

Browse files
committed
Inline pair production in json parser
Having this as a separate production has a noticeable performance impact, and doesn't really make things clearer either.
1 parent a08a2b4 commit f5be0e5

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

ext/json/json_parser.y

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ int json_yydebug = 1;
4747

4848
%union {
4949
zval value;
50-
struct {
51-
zend_string *key;
52-
zval val;
53-
} pair;
5450
}
5551

5652

@@ -66,10 +62,8 @@ int json_yydebug = 1;
6662

6763
%type <value> start object key value array
6864
%type <value> members member elements element
69-
%type <pair> pair
7065

7166
%destructor { zval_ptr_dtor_nogc(&$$); } <value>
72-
%destructor { zend_string_release_ex($$.key, 0); zval_ptr_dtor_nogc(&$$.val); } <pair>
7367

7468
%code {
7569
static int php_json_yylex(union YYSTYPE *value, php_json_parser *parser);
@@ -130,30 +124,22 @@ members:
130124
;
131125

132126
member:
133-
pair
127+
key ':' value
134128
{
135129
parser->methods.object_create(parser, &$$);
136-
if (parser->methods.object_update(parser, &$$, $1.key, &$1.val) == FAILURE) {
130+
if (parser->methods.object_update(parser, &$$, Z_STR($1), &$3) == FAILURE) {
137131
YYERROR;
138132
}
139133
}
140-
| member ',' pair
134+
| member ',' key ':' value
141135
{
142-
if (parser->methods.object_update(parser, &$1, $3.key, &$3.val) == FAILURE) {
136+
if (parser->methods.object_update(parser, &$1, Z_STR($3), &$5) == FAILURE) {
143137
YYERROR;
144138
}
145139
ZVAL_COPY_VALUE(&$$, &$1);
146140
}
147141
;
148142

149-
pair:
150-
key ':' value
151-
{
152-
$$.key = Z_STR($1);
153-
ZVAL_COPY_VALUE(&$$.val, &$3);
154-
}
155-
;
156-
157143
array:
158144
'['
159145
{

0 commit comments

Comments
 (0)