diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp index 8c16bc5f1..e8116a36f 100644 --- a/include/nlohmann/detail/output/serializer.hpp +++ b/include/nlohmann/detail/output/serializer.hpp @@ -82,7 +82,7 @@ class serializer being threaded through every call to @ref dump, @ref dump_internal and @ref dump_iteratively. */ - serializer(output_adapter_protocol& s, const char ichar, + serializer(output_adapter_protocol& s, const char ichar, // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init): the buffers are written before they are read const bool pretty_print_ = false, const bool ensure_ascii_ = false, const std::size_t indent_step_ = 0, @@ -2050,11 +2050,15 @@ class serializer /// the output of the serializer (non-owning; the adapter lives at the call site) output_adapter_protocol* o = nullptr; + // The three buffers below are left uninitialized: they are written before they + // are read (only the part written is ever read), and zeroing 1.6 KiB took + // more than half of what dumping a small value costs. + /// a (hopefully) large enough character buffer - std::array number_buffer{{}}; + std::array number_buffer; // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init) /// string buffer - std::array string_buffer{{}}; + std::array string_buffer; // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init) /// the indentation character const char indent_char; @@ -2074,7 +2078,7 @@ class serializer /// buffer collecting output before it is flushed to the output adapter, so /// that the many small structural writes become few bulk writes static constexpr std::size_t write_buffer_size = 1024; - std::array write_buffer{{}}; + std::array write_buffer; // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init) /// number of valid bytes currently held in @ref write_buffer std::size_t write_buffer_pos = 0; }; diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 80690adc0..6552900c9 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -30226,7 +30226,7 @@ class serializer being threaded through every call to @ref dump, @ref dump_internal and @ref dump_iteratively. */ - serializer(output_adapter_protocol& s, const char ichar, + serializer(output_adapter_protocol& s, const char ichar, // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init): the buffers are written before they are read const bool pretty_print_ = false, const bool ensure_ascii_ = false, const std::size_t indent_step_ = 0, @@ -32194,11 +32194,15 @@ class serializer /// the output of the serializer (non-owning; the adapter lives at the call site) output_adapter_protocol* o = nullptr; + // The three buffers below are left uninitialized: they are written before they + // are read (only the part written is ever read), and zeroing 1.6 KiB took + // more than half of what dumping a small value costs. + /// a (hopefully) large enough character buffer - std::array number_buffer{{}}; + std::array number_buffer; // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init) /// string buffer - std::array string_buffer{{}}; + std::array string_buffer; // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init) /// the indentation character const char indent_char; @@ -32218,7 +32222,7 @@ class serializer /// buffer collecting output before it is flushed to the output adapter, so /// that the many small structural writes become few bulk writes static constexpr std::size_t write_buffer_size = 1024; - std::array write_buffer{{}}; + std::array write_buffer; // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init) /// number of valid bytes currently held in @ref write_buffer std::size_t write_buffer_pos = 0; };