aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2015-05-04 09:00:26 +0300
committerPetri Lehtinen <petri@digip.org>2015-05-04 09:00:26 +0300
commitd384acd706c78918766a1ec925b66ac3d2d30278 (patch)
treedbdbfc630a86a204535614b09b3bdd29480075ed
parentd8753db4ace03e8fa317875ab516f2e6e71375ff (diff)
parent5d42e1520ad420bdc3feb1cf41f8dd1e53a5a1b1 (diff)
downloadjansson-d384acd706c78918766a1ec925b66ac3d2d30278.zip
jansson-d384acd706c78918766a1ec925b66ac3d2d30278.tar.gz
jansson-d384acd706c78918766a1ec925b66ac3d2d30278.tar.bz2
Merge pull request #234 from flok99/master
Optimized dump_indent to reduce the number of fwrite calls.
-rw-r--r--src/dump.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/dump.c b/src/dump.c
index 018893f..1a4e176 100644
--- a/src/dump.c
+++ b/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)
{
- 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))
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;
+
+ n_spaces -= cur_n;
}
}
else if(space && !(flags & JSON_COMPACT))