From 11791e2a50417661679f84aeae21ce959cab638f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 12 May 2022 12:31:17 +0200 Subject: [PATCH] QVarLengthArray: Move unique_ptr to QVLABaseBase MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This avoids repeated re-instantiations of unique_ptr with local deleters, removing that instantiation from the top of the list in Clang -ftime-trace QtWidgets builds: **** Templates that took longest to instantiate: 2627 ms: std::__1::unique_ptr (835 times, avg 3 ms) Amends e297e80fd0ec6ce4c97ee1b40426c76377b45ecc. Pick-to: 6.3 Task-number: QTBUG-97601 Task-number: QTBUG-99039 Change-Id: I1281f6cf9248a3796d9dfdc653f19f5a67dc3bda Reviewed-by: MÃ¥rten Nordheim --- src/corelib/tools/qvarlengtharray.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index 5898e486f9d..261cdcb5cde 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -96,6 +96,11 @@ protected: Q_ASSERT(n <= size() - pos); } + struct free_deleter { + void operator()(void *p) const noexcept { free(p); } + }; + using malloced_ptr = std::unique_ptr; + public: using size_type = qsizetype; @@ -748,10 +753,7 @@ Q_OUTOFLINE_TEMPLATE void QVLABase::reallocate_impl(qsizetype prealloc, void Q_ASSUME(copySize >= 0); if (aalloc != capacity()) { - struct free_deleter { - void operator()(void *p) const noexcept { free(p); } - }; - std::unique_ptr guard; + QVLABaseBase::malloced_ptr guard; void *newPtr; qsizetype newA; if (aalloc > prealloc) {