diff options
author | Robert Löhning <robert.loehning@qt.io> | 2021-10-18 15:00:09 +0200 |
---|---|---|
committer | Robert Löhning <robert.loehning@qt.io> | 2021-10-23 01:22:15 +0200 |
commit | a7d1c48ca3162a805708d059da87ca3d742863f1 (patch) | |
tree | 5e1ef71696d5a49f7ae78eeab3d12b18f8f0bdf3 /src | |
parent | fdbf7cdd09fb5d32d74908a22bbc4459ed2b5517 (diff) |
QVarLengthArray: Reduce memory allocations in emplace()
Currently, we allocate memory for elements one by one which can get
pretty slow when adding many elements.
[ChangeLog][QtCore][QVarLengthArray] Reduced number of memory
allocations in emplace() by allocating more memory at once.
Fixes: QTBUG-97489
Pick-to: 6.2
Change-Id: Idfb5b5946b047d5215c8ed00770574249f9f5d40
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qvarlengtharray.h | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index 90be3b3299..6ecc22213f 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -621,7 +621,8 @@ Q_OUTOFLINE_TEMPLATE auto QVarLengthArray<T, Prealloc>::emplace(const_iterator b Q_ASSERT_X(isValidIterator(before), "QVarLengthArray::insert", "The specified const_iterator argument 'before' is invalid"); qsizetype offset = qsizetype(before - ptr); - reserve(s + 1); + if (s == a) + reserve(s * 2); if (!QTypeInfo<T>::isRelocatable) { T *b = ptr + offset; T *i = ptr + s; |