diff options
author | Petri Lehtinen <petri@digip.org> | 2015-05-04 09:00:26 +0300 |
---|---|---|
committer | Petri Lehtinen <petri@digip.org> | 2015-05-04 09:00:26 +0300 |
commit | d384acd706c78918766a1ec925b66ac3d2d30278 (patch) | |
tree | dbdbfc630a86a204535614b09b3bdd29480075ed | |
parent | d8753db4ace03e8fa317875ab516f2e6e71375ff (diff) | |
parent | 5d42e1520ad420bdc3feb1cf41f8dd1e53a5a1b1 (diff) | |
download | jansson-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.c | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -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)) |