Document that keys() and values() run in linear time

keys() and values() can be slower for large containers.
I ran into this recently when profiling, and was surprised that keys()
had to build the list of keys (by appending in a loop).

Pick-to: 5.15 5.12
Change-Id: I73215f5a917790236704ad7ef78cefc4a049cd89
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Mitch Curtis 2020-06-22 10:04:04 +02:00
parent 46ec92dad0
commit 13c90a0a75
3 changed files with 28 additions and 0 deletions

View File

@ -1431,6 +1431,10 @@ size_t qHash(long double key, size_t seed) noexcept
The order is guaranteed to be the same as that used by values(). The order is guaranteed to be the same as that used by values().
This function creates a new list, in \l {linear time}. The time and memory
use that entails can be avoided by iterating from \l keyBegin() to
\l keyEnd().
\sa values(), key() \sa values(), key()
*/ */
@ -1453,6 +1457,10 @@ size_t qHash(long double key, size_t seed) noexcept
The order is guaranteed to be the same as that used by keys(). The order is guaranteed to be the same as that used by keys().
This function creates a new list, in \l {linear time}. The time and memory
use that entails can be avoided by iterating from \l keyValueBegin() to
\l keyValueEnd().
\sa keys(), value() \sa keys(), value()
*/ */
@ -2518,6 +2526,10 @@ size_t qHash(long double key, size_t seed) noexcept
The order is guaranteed to be the same as that used by values(). The order is guaranteed to be the same as that used by values().
This function creates a new list, in \l {linear time}. The time and memory
use that entails can be avoided by iterating from \l keyBegin() to
\l keyEnd().
\sa values(), key() \sa values(), key()
*/ */
@ -2530,6 +2542,10 @@ size_t qHash(long double key, size_t seed) noexcept
The order is guaranteed to be the same as that used by keys(). The order is guaranteed to be the same as that used by keys().
This function creates a new list, in \l {linear time}. The time and memory
use that entails can be avoided by iterating from \l keyValueBegin() to
\l keyValueEnd().
\sa keys(), value() \sa keys(), value()
*/ */

View File

@ -759,6 +759,10 @@ void QMapDataBase::freeData(QMapDataBase *d)
The order is guaranteed to be the same as that used by values(). The order is guaranteed to be the same as that used by values().
This function creates a new list, in \l {linear time}. The time and memory
use that entails can be avoided by iterating from \l keyBegin() to
\l keyEnd().
\sa QMultiMap::uniqueKeys(), values(), key() \sa QMultiMap::uniqueKeys(), values(), key()
*/ */
@ -798,6 +802,10 @@ void QMapDataBase::freeData(QMapDataBase *d)
all of its values will be in the list, and not just the most all of its values will be in the list, and not just the most
recently inserted one. recently inserted one.
This function creates a new list, in \l {linear time}. The time and memory
use that entails can be avoided by iterating from \l keyValueBegin() to
\l keyValueEnd().
\sa keys(), value() \sa keys(), value()
*/ */

View File

@ -1093,6 +1093,10 @@
\include containers-range-constructor.qdocinc \include containers-range-constructor.qdocinc
This function creates a new list, in \l {linear time}. The time and memory
use that entails can be avoided by iterating from \l constBegin() to
\l constEnd().
\sa fromList(), QList::fromSet() \sa fromList(), QList::fromSet()
*/ */