Skip to content

Commit aea6397

Browse files
authored
Update json_encoder.c
1 parent 42b9ba6 commit aea6397

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

ext/json/json_encoder.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,11 @@ 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-
int depth = encoder->depth;
58-
if (depth <= 4) {
59-
int i;
60-
for (i = 0; i < depth; i++) {
61-
smart_str_appendl(buf, " ", 4);
62-
}
63-
} else {
64-
size_t remaining = (size_t) depth * 4;
65-
char *dst = smart_str_extend(buf, remaining);
66-
memset(dst, ' ', remaining);
57+
int i;
58+
smart_str_alloc(buf, encoder->depth * 4, 0);
59+
60+
for (i = 0; i < encoder->depth; ++i) {
61+
smart_str_appendl(buf, " ", 4);
6762
}
6863
}
6964
}

0 commit comments

Comments
 (0)