From 32853d2c905133230968c6fc69aad96e55c21040 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Fri, 9 Oct 2026 23:22:34 +0200 Subject: [PATCH] Do not shrink the output of dump() finish() copied the whole output when the buffer was more than twice as large as the result (citm dump +11%). The tighter source_extent() estimate already keeps the buffer of a small value small. Signed-off-by: Niels Lohmann --- include/nlohmann/detail/view/serializer.hpp | 5 ----- single_include/nlohmann/json_view.hpp | 5 ----- 2 files changed, 10 deletions(-) diff --git a/include/nlohmann/detail/view/serializer.hpp b/include/nlohmann/detail/view/serializer.hpp index 7870601bc..bde8797c5 100644 --- a/include/nlohmann/detail/view/serializer.hpp +++ b/include/nlohmann/detail/view/serializer.hpp @@ -46,11 +46,6 @@ class output_buffer { const auto size = static_cast(m_pos - m_out.data()); m_out.resize(size); - // do not keep a buffer that was sized for a much larger output - if (m_out.capacity() > 1024 && m_out.capacity() / 2 > size) - { - m_out.shrink_to_fit(); - } } NLOHMANN_VIEW_ALWAYS_INLINE void reserve(std::size_t n) diff --git a/single_include/nlohmann/json_view.hpp b/single_include/nlohmann/json_view.hpp index 273e11474..5cd836097 100644 --- a/single_include/nlohmann/json_view.hpp +++ b/single_include/nlohmann/json_view.hpp @@ -3108,11 +3108,6 @@ class output_buffer { const auto size = static_cast(m_pos - m_out.data()); m_out.resize(size); - // do not keep a buffer that was sized for a much larger output - if (m_out.capacity() > 1024 && m_out.capacity() / 2 > size) - { - m_out.shrink_to_fit(); - } } NLOHMANN_VIEW_ALWAYS_INLINE void reserve(std::size_t n)