qt5base-lts/tests/auto/corelib/tools/qhash
Ivan Solovev b095d26878 QHash/QSet: fix squeeze() for default-constructed container
QHash::squeeze() was unconditionally calling reserve(0), which is
always allocating memory (even for 0 size).
This was leading to a confusing situation when calling squeeze() on
a default-constructed container with 0 capacity() actually allocated
memory. This is very misleading, as squeeze() is supposed to free
unneeded memory, not to allocate more.

This patch adds a check for non-zero capacity. As a result, nothing
is done for default-constructed container.

Note that this patch also affects the QSet::squeeze() behavior, because
QSet uses QHash as its underlying data type.

Task-number: QTBUG-91736
Pick-to: 6.2 6.1
Change-Id: Ib1c3c8b7b3de6ddeefea0e70b1ec71803e8fd3b3
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Andreas Buhr <andreas.buhr@qt.io>
2021-07-27 20:57:49 +02:00
..
.gitignore Moving relevant tests to corelib/tools 2011-09-01 13:07:23 +02:00
CMakeLists.txt CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
tst_qhash.cpp QHash/QSet: fix squeeze() for default-constructed container 2021-07-27 20:57:49 +02:00