Skip to content

Commit 6c5cd75

Browse files
committed
Revert "Update json_encoder.c"
This reverts commit cd9192c.
1 parent cd9192c commit 6c5cd75

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

ext/json/json_encoder.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,19 @@ static inline void php_json_pretty_print_char(smart_str *buf, int options, char
5353

5454
static inline void php_json_pretty_print_indent(smart_str *buf, int options, const php_json_encoder *encoder) /* {{{ */
5555
{
56-
if (options & PHP_JSON_PRETTY_PRINT) {
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);
68-
}
69-
}
56+
if (options & PHP_JSON_PRETTY_PRINT) {
57+
int depth = encoder->depth;
58+
if (depth <= 8) {
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);
67+
}
68+
}
7069
}
7170
/* }}} */
7271

0 commit comments

Comments
 (0)