Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ PHP 8.6 UPGRADE NOTES

- JSON:
. Improve performance of encoding arrays and objects.
. Improved performance of indentation generation in json_encode()
when using PHP_JSON_PRETTY_PRINT.

- Standard:
. Improved performance of array_fill_keys().
Expand Down
13 changes: 11 additions & 2 deletions ext/json/json_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,17 @@ static inline void php_json_pretty_print_char(smart_str *buf, int options, char
static inline void php_json_pretty_print_indent(smart_str *buf, int options, const php_json_encoder *encoder) /* {{{ */
{
if (options & PHP_JSON_PRETTY_PRINT) {
for (int i = 0; i < encoder->depth; ++i) {
smart_str_appendl(buf, " ", 4);
static const char spaces[] =
Comment thread
LamentXU123 marked this conversation as resolved.
Outdated
" ";
size_t remaining = (size_t) encoder->depth * 4;

while (remaining >= sizeof(spaces) - 1) {
smart_str_appendl(buf, spaces, sizeof(spaces) - 1);
remaining -= sizeof(spaces) - 1;
}

if (remaining) {
smart_str_appendl(buf, spaces, remaining);
}
}
}
Expand Down
Loading