From 888cfb4293e44345aecc76409bbfb214214ecc38 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 20 Oct 2026 22:38:05 +0200 Subject: [PATCH] Explain why the growth of the dump's stack is static Signed-off-by: Niels Lohmann --- include/nlohmann/detail/view/serializer.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/nlohmann/detail/view/serializer.hpp b/include/nlohmann/detail/view/serializer.hpp index 64db2eb14..5d1074820 100644 --- a/include/nlohmann/detail/view/serializer.hpp +++ b/include/nlohmann/detail/view/serializer.hpp @@ -174,8 +174,11 @@ inline std::size_t plain_output_run(const unsigned char* s, std::size_t n) noexc /// A stack that starts in a buffer of the caller (a local array) and moves to /// the heap (a vector of the caller) only when that is full, so that dumps of /// shallow documents need no allocation. The top is a pointer, as in -/// std::vector. The address of the stack never escapes (the growth gets the -/// vector and returns the new storage), so its pointers stay in registers. +/// std::vector. grow() is static and out of line: it gets the vector and the +/// used range and returns the new storage, so the address of the stack never +/// reaches a call. Otherwise the compiler would have to keep the three +/// pointers in memory and load and store them on every push_back() and +/// pop_back(), not just when growing. template class small_stack {