mirror of https://github.com/akheron/jansson
Optimized dump_indent to reduce the number of fwrite calls.
This commit is contained in:
parent
d8753db4ac
commit
5d42e1520a
10
src/dump.c
10
src/dump.c
|
@ -50,15 +50,19 @@ static int dump_indent(size_t flags, int depth, int space, json_dump_callback_t
|
||||||
{
|
{
|
||||||
if(FLAGS_TO_INDENT(flags) > 0)
|
if(FLAGS_TO_INDENT(flags) > 0)
|
||||||
{
|
{
|
||||||
int i, ws_count = FLAGS_TO_INDENT(flags);
|
unsigned int ws_count = FLAGS_TO_INDENT(flags), n_spaces = depth * ws_count;
|
||||||
|
|
||||||
if(dump("\n", 1, data))
|
if(dump("\n", 1, data))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for(i = 0; i < depth; i++)
|
while(n_spaces > 0)
|
||||||
{
|
{
|
||||||
if(dump(whitespace, ws_count, data))
|
int cur_n = n_spaces < sizeof whitespace - 1 ? n_spaces : sizeof whitespace - 1;
|
||||||
|
|
||||||
|
if(dump(whitespace, cur_n, data))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
n_spaces -= cur_n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(space && !(flags & JSON_COMPACT))
|
else if(space && !(flags & JSON_COMPACT))
|
||||||
|
|
Loading…
Reference in New Issue