From: Nikita Popov Date: Fri, 13 Nov 2020 13:55:26 +0000 (+0100) Subject: Inline pair production in json parser X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f5be0e5110ff816d2ce168c154cb3575d08e3cad;p=php 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. --- diff --git a/ext/json/json_parser.y b/ext/json/json_parser.y index 77df0eef6a..8186040088 100644 --- a/ext/json/json_parser.y +++ b/ext/json/json_parser.y @@ -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 start object key value array %type members member elements element -%type pair %destructor { zval_ptr_dtor_nogc(&$$); } -%destructor { zend_string_release_ex($$.key, 0); zval_ptr_dtor_nogc(&$$.val); } %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: '[' {