]> granicus.if.org Git - php/commitdiff
Inline pair production in json parser
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 13 Nov 2020 13:55:26 +0000 (14:55 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 13 Nov 2020 13:56:29 +0000 (14:56 +0100)
Having this as a separate production has a noticeable performance
impact, and doesn't really make things clearer either.

ext/json/json_parser.y

index 77df0eef6a5726f75b4e747329abeb732c4ced99..8186040088099184ceaa60140c64598691796463 100644 (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:
                '['
                        {