From be29c4053e00f80964a1a997111d89e7a96adb7d Mon Sep 17 00:00:00 2001 From: Alejandro Exojo Date: Fri, 13 Dec 2013 11:28:59 +0100 Subject: Clarify foreach's documentation on valued-containers - Explain that values() is unnecessary and causes an extra copy. - Replace "are fastest" with "are faster". - Briefly explain the snippet. Change-Id: Iff1d3a0b6140fca1d78157aeeca3d538c4d78b84 Reviewed-by: Albert Astals Cid Reviewed-by: Thiago Macieira --- src/corelib/doc/src/containers.qdoc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/corelib/doc/src') diff --git a/src/corelib/doc/src/containers.qdoc b/src/corelib/doc/src/containers.qdoc index fa26409d83..6017269272 100644 --- a/src/corelib/doc/src/containers.qdoc +++ b/src/corelib/doc/src/containers.qdoc @@ -578,9 +578,11 @@ \snippet code/doc_src_containers.cpp 18 With QMap and QHash, \c foreach accesses the value component of - the (key, value) pairs. If you want to iterate over both the keys - and the values, you can use iterators (which are fastest), or you - can write code like this: + the (key, value) pairs automatically, so you should not call + values() on the container (it would generate an unnecessary copy, + see below). If you want to iterate over both the keys and the + values, you can use iterators (which are faster), or you can + obtain the keys, and use them to get the values too: \snippet code/doc_src_containers.cpp 19 -- cgit v1.2.3