diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2022-04-12 17:17:20 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2022-04-12 22:38:31 +0100 |
commit | b2c007b87dcd5db5d59447de2081777aea66f35f (patch) | |
tree | 285fac827988c1854b25808b40f2dfea0c5429a0 /libstdc++-v3 | |
parent | 7cf88759957a7006e1e1d0a82a1a4de3c4db109e (diff) | |
download | gcc-b2c007b87dcd5db5d59447de2081777aea66f35f.zip gcc-b2c007b87dcd5db5d59447de2081777aea66f35f.tar.gz gcc-b2c007b87dcd5db5d59447de2081777aea66f35f.tar.bz2 |
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.
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/include/std/stacktrace | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/libstdc++-v3/include/std/stacktrace b/libstdc++-v3/include/std/stacktrace index 382d900..98ce923 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; } |