public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-8124] libstdc++: shrink-to-fit in std::basic_stacktrace::current(skip, max) Date: Tue, 12 Apr 2022 21:39:37 +0000 (GMT) [thread overview] Message-ID: <20220412213937.C4B973858C27@sourceware.org> (raw) https://gcc.gnu.org/g:b2c007b87dcd5db5d59447de2081777aea66f35f commit r12-8124-gb2c007b87dcd5db5d59447de2081777aea66f35f Author: Jonathan Wakely <jwakely@redhat.com> Date: Tue Apr 12 17:17:20 2022 +0100 libstdc++: shrink-to-fit in std::basic_stacktrace::current(skip, max) If a large stacktrace is reduced to a max depth that is less than half the capacity it will now be reallocated to remove the unused capacity. libstdc++-v3/ChangeLog: * include/std/stacktrace (basic_stacktrace::current): Reallocate a smaller container if the unused capacity is larger than the used size. Diff: --- libstdc++-v3/include/std/stacktrace | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/stacktrace b/libstdc++-v3/include/std/stacktrace index 382d900a822..98ce9231150 100644 --- a/libstdc++-v3/include/std/stacktrace +++ b/libstdc++-v3/include/std/stacktrace @@ -289,7 +289,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (__err < 0) __ret._M_clear(); else if (__ret.size() > __max_depth) - __ret._M_impl._M_resize(__max_depth, __ret._M_alloc); + { + __ret._M_impl._M_resize(__max_depth, __ret._M_alloc); + + if (__ret._M_impl._M_capacity / 2 >= __max_depth) + { + // shrink to fit + _Impl __tmp = __ret._M_impl._M_clone(__ret._M_alloc); + if (__tmp._M_capacity) + { + __ret._M_clear(); + __ret._M_impl = __tmp; + } + } + } } return __ret; }
reply other threads:[~2022-04-12 21:39 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220412213937.C4B973858C27@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).