summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-10-30 11:06:59 +0100
committerNikita Popov <nikita.ppv@gmail.com>2019-10-30 11:06:59 +0100
commit9241037837a2f14a0a88af9d494d136ac16446ae (patch)
tree34e493cf59eaf7277dd228d95f10925ccaac8076
parente0a401335dfe15af026be2281a23969ad892b7a1 (diff)
parent447f07cd28494caf6c9f08640bc6d355f93ed2f2 (diff)
downloadphp-git-9241037837a2f14a0a88af9d494d136ac16446ae.tar.gz
Merge branch 'PHP-7.4'
* PHP-7.4: Optimize creation of empty arrays in json_decode
-rw-r--r--ext/json/json_parser.y14
1 files changed, 12 insertions, 2 deletions
diff --git a/ext/json/json_parser.y b/ext/json/json_parser.y
index 2f8a260c98..ec5e4e81cf 100644
--- a/ext/json/json_parser.y
+++ b/ext/json/json_parser.y
@@ -74,6 +74,8 @@ int json_yydebug = 1;
%code {
static int php_json_yylex(union YYSTYPE *value, php_json_parser *parser);
static void php_json_yyerror(php_json_parser *parser, char const *msg);
+static int php_json_parser_array_create(php_json_parser *parser, zval *array);
+static int php_json_parser_object_create(php_json_parser *parser, zval *array);
}
@@ -118,7 +120,11 @@ object_end:
members:
/* empty */
{
- parser->methods.object_create(parser, &$$);
+ if ((parser->scanner.options & PHP_JSON_OBJECT_AS_ARRAY) && parser->methods.object_create == php_json_parser_object_create) {
+ ZVAL_EMPTY_ARRAY(&$$);
+ } else {
+ parser->methods.object_create(parser, &$$);
+ }
}
| member
;
@@ -178,7 +184,11 @@ array_end:
elements:
/* empty */
{
- parser->methods.array_create(parser, &$$);
+ if (parser->methods.array_create == php_json_parser_array_create) {
+ ZVAL_EMPTY_ARRAY(&$$);
+ } else {
+ parser->methods.array_create(parser, &$$);
+ }
}
| element
;