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.
This commit is contained in:
Nikita Popov 2020-11-13 14:55:26 +01:00
parent a08a2b48b4
commit f5be0e5110

View File

@ -47,10 +47,6 @@ int json_yydebug = 1;
%union {
zval value;
struct {
zend_string *key;
zval val;
} pair;
}
@ -66,10 +62,8 @@ int json_yydebug = 1;
%type <value> start object key value array
%type <value> members member elements element
%type <pair> pair
%destructor { zval_ptr_dtor_nogc(&$$); } <value>
%destructor { zend_string_release_ex($$.key, 0); zval_ptr_dtor_nogc(&$$.val); } <pair>
%code {
static int php_json_yylex(union YYSTYPE *value, php_json_parser *parser);
@ -130,30 +124,22 @@ members:
;
member:
pair
key ':' value
{
parser->methods.object_create(parser, &$$);
if (parser->methods.object_update(parser, &$$, $1.key, &$1.val) == FAILURE) {
if (parser->methods.object_update(parser, &$$, Z_STR($1), &$3) == FAILURE) {
YYERROR;
}
}
| member ',' pair
| member ',' key ':' value
{
if (parser->methods.object_update(parser, &$1, $3.key, &$3.val) == FAILURE) {
if (parser->methods.object_update(parser, &$1, Z_STR($3), &$5) == FAILURE) {
YYERROR;
}
ZVAL_COPY_VALUE(&$$, &$1);
}
;
pair:
key ':' value
{
$$.key = Z_STR($1);
ZVAL_COPY_VALUE(&$$.val, &$3);
}
;
array:
'['
{