From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 370283858C56 for ; Tue, 12 Apr 2022 21:41:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 370283858C56 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-542-D-99Na6NPkKiRgu_sAVnhw-1; Tue, 12 Apr 2022 17:41:32 -0400 X-MC-Unique: D-99Na6NPkKiRgu_sAVnhw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 383B4101A52C; Tue, 12 Apr 2022 21:41:32 +0000 (UTC) Received: from localhost (unknown [10.33.36.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id F0D99C15D4F; Tue, 12 Apr 2022 21:41:31 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed 4/5] libstdc++: shrink-to-fit in std::basic_stacktrace::current(skip, max) Date: Tue, 12 Apr 2022 22:41:27 +0100 Message-Id: <20220412214128.509227-4-jwakely@redhat.com> In-Reply-To: <20220412214128.509227-1-jwakely@redhat.com> References: <20220412214128.509227-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Apr 2022 21:41:35 -0000 Tested powerpc64-linux, pushed to trunk. -- >8 -- 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. --- 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; } -- 2.34.1