Skip to content

Commit 1d40408

Browse files
committed
Update json_encoder.c
1 parent 38cbbee commit 1d40408

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

ext/json/json_encoder.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,17 @@ static inline void php_json_pretty_print_char(smart_str *buf, int options, char
5454
static inline void php_json_pretty_print_indent(smart_str *buf, int options, const php_json_encoder *encoder) /* {{{ */
5555
{
5656
if (options & PHP_JSON_PRETTY_PRINT) {
57-
for (int i = 0; i < encoder->depth; ++i) {
58-
smart_str_appendl(buf, " ", 4);
57+
static const char spaces[] =
58+
" ";
59+
size_t remaining = (size_t) encoder->depth * 4;
60+
61+
while (remaining >= sizeof(spaces) - 1) {
62+
smart_str_appendl(buf, spaces, sizeof(spaces) - 1);
63+
remaining -= sizeof(spaces) - 1;
64+
}
65+
66+
if (remaining) {
67+
smart_str_appendl(buf, spaces, remaining);
5968
}
6069
}
6170
}

0 commit comments

Comments
 (0)