mirror of
https://github.com/nlohmann/json.git
synced 2026-09-06 08:17:59 +00:00
The serializer constructor unconditionally allocated a 512-byte indent_string, even though it is only ever read inside the pretty_print branches of dump(). This wasted a heap allocation (and its matching deallocation) on every compact (i.e. default, non-pretty) dump() call. indent_string is now default-constructed empty and lazily grown to 512 bytes, filled with indent_char, the first time a pretty-print branch actually needs it. The existing doubling/growth logic for larger indents is otherwise untouched, so output remains byte-identical to before -- including in the pre-existing edge case where growth beyond the initial buffer fills with ' ' instead of indent_char (tracked separately by open PR #5186, which is left alone here). The second, larger optimization mentioned in #5413 (removing the shared_ptr-based output adapter) is intentionally out of scope, as it overlaps open PR #5285. Fixes #5413 Signed-off-by: Niels Lohmann <mail@nlohmann.me>