Skip to content

Commit 9241037

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Optimize creation of empty arrays in json_decode
2 parents e0a4013 + 447f07c commit 9241037

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

ext/json/json_parser.y

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ int json_yydebug = 1;
7474
%code {
7575
static int php_json_yylex(union YYSTYPE *value, php_json_parser *parser);
7676
static void php_json_yyerror(php_json_parser *parser, char const *msg);
77+
static int php_json_parser_array_create(php_json_parser *parser, zval *array);
78+
static int php_json_parser_object_create(php_json_parser *parser, zval *array);
7779

7880
}
7981

@@ -118,7 +120,11 @@ object_end:
118120
members:
119121
/* empty */
120122
{
121-
parser->methods.object_create(parser, &$$);
123+
if ((parser->scanner.options & PHP_JSON_OBJECT_AS_ARRAY) && parser->methods.object_create == php_json_parser_object_create) {
124+
ZVAL_EMPTY_ARRAY(&$$);
125+
} else {
126+
parser->methods.object_create(parser, &$$);
127+
}
122128
}
123129
| member
124130
;
@@ -178,7 +184,11 @@ array_end:
178184
elements:
179185
/* empty */
180186
{
181-
parser->methods.array_create(parser, &$$);
187+
if (parser->methods.array_create == php_json_parser_array_create) {
188+
ZVAL_EMPTY_ARRAY(&$$);
189+
} else {
190+
parser->methods.array_create(parser, &$$);
191+
}
182192
}
183193
| element
184194
;

0 commit comments

Comments
 (0)