QVarLengthArray: Move unique_ptr<void, free_deleter> to QVLABaseBase

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<void, free_deleter> (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 <marten.nordheim@qt.io>
This commit is contained in:
Marc Mutz 2022-05-12 12:31:17 +02:00
parent 250f5f4a11
commit 11791e2a50

View File

@ -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<void, free_deleter>;
public:
using size_type = qsizetype;
@ -748,10 +753,7 @@ Q_OUTOFLINE_TEMPLATE void QVLABase<T>::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<void, free_deleter> guard;
QVLABaseBase::malloced_ptr guard;
void *newPtr;
qsizetype newA;
if (aalloc > prealloc) {