diff options
author | Olivier Goffart <olivier.goffart@nokia.com> | 2010-07-26 12:03:00 (GMT) |
---|---|---|
committer | Olivier Goffart <olivier.goffart@nokia.com> | 2010-07-26 14:04:18 (GMT) |
commit | a882a46b1c60e5774ade68eaac60922b19a08835 (patch) | |
tree | d603f2ad38e235392e3bccdee51836c2667cfda7 /doc/src | |
parent | 3a08c5b1682e211bf664c21850187e2b15e89c23 (diff) | |
download | Qt-a882a46b1c60e5774ade68eaac60922b19a08835.zip Qt-a882a46b1c60e5774ade68eaac60922b19a08835.tar.gz Qt-a882a46b1c60e5774ade68eaac60922b19a08835.tar.bz2 |
Doc: use const& in foreach when applicable.
Const reference are slightly faster than doing a copy of the object
on each iteration.
Lead by example by having this pattern right in our documentation
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/snippets/code/doc_src_containers.qdoc | 8 | ||||
-rw-r--r-- | doc/src/snippets/code/doc_src_qalgorithms.qdoc | 2 | ||||
-rw-r--r-- | doc/src/snippets/code/doc_src_qset.qdoc | 2 | ||||
-rw-r--r-- | doc/src/snippets/code/doc_src_qt4-tulip.qdoc | 2 | ||||
-rw-r--r-- | doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp | 2 | ||||
-rw-r--r-- | doc/src/snippets/code/src_gui_kernel_qapplication.cpp | 4 | ||||
-rw-r--r-- | doc/src/snippets/code/src_network_kernel_qhostinfo.cpp | 2 | ||||
-rw-r--r-- | doc/src/snippets/code/src_network_ssl_qsslcertificate.cpp | 2 | ||||
-rw-r--r-- | doc/src/snippets/droparea.cpp | 2 | ||||
-rw-r--r-- | doc/src/snippets/picture/picture.cpp | 4 | ||||
-rw-r--r-- | doc/src/snippets/qfontdatabase/main.cpp | 4 | ||||
-rw-r--r-- | doc/src/snippets/qlistview-dnd/model.cpp | 4 | ||||
-rw-r--r-- | doc/src/snippets/qstringlist/main.cpp | 2 | ||||
-rw-r--r-- | doc/src/snippets/qtreeview-dnd/dragdropmodel.cpp | 2 | ||||
-rw-r--r-- | doc/src/snippets/widgets-tutorial/nestedlayouts/main.cpp | 4 |
15 files changed, 23 insertions, 23 deletions
diff --git a/doc/src/snippets/code/doc_src_containers.qdoc b/doc/src/snippets/code/doc_src_containers.qdoc index 5cf2aab..1f86f60 100644 --- a/doc/src/snippets/code/doc_src_containers.qdoc +++ b/doc/src/snippets/code/doc_src_containers.qdoc @@ -216,7 +216,7 @@ while (i.hasNext()) //! [17] QLinkedList<QString> list; ... -foreach (QString str, list) +foreach (const QString &str, list) qDebug() << str; //! [17] @@ -224,7 +224,7 @@ foreach (QString str, list) //! [18] QLinkedList<QString> list; ... -foreach (QString str, list) { +foreach (const QString &str, list) { if (str.isEmpty()) break; qDebug() << str; @@ -235,7 +235,7 @@ foreach (QString str, list) { //! [19] QMap<QString, int> map; ... -foreach (QString str, map.keys()) +foreach (const QString &str, map.keys()) qDebug() << str << ":" << map.value(str); //! [19] @@ -243,7 +243,7 @@ foreach (QString str, map.keys()) //! [20] QMultiMap<QString, int> map; ... -foreach (QString str, map.uniqueKeys()) { +foreach (const QString &str, map.uniqueKeys()) { foreach (int i, map.values(str)) qDebug() << str << ":" << i; } diff --git a/doc/src/snippets/code/doc_src_qalgorithms.qdoc b/doc/src/snippets/code/doc_src_qalgorithms.qdoc index 78634a2..f5a73c6 100644 --- a/doc/src/snippets/code/doc_src_qalgorithms.qdoc +++ b/doc/src/snippets/code/doc_src_qalgorithms.qdoc @@ -217,7 +217,7 @@ QStringList list; list << "AlPha" << "beTA" << "gamma" << "DELTA"; QMap<QString, QString> map; -foreach (QString str, list) +foreach (const QString &str, list) map.insert(str.toLower(), str); list = map.values(); diff --git a/doc/src/snippets/code/doc_src_qset.qdoc b/doc/src/snippets/code/doc_src_qset.qdoc index ac48edb..c6e1933 100644 --- a/doc/src/snippets/code/doc_src_qset.qdoc +++ b/doc/src/snippets/code/doc_src_qset.qdoc @@ -80,7 +80,7 @@ while (i != set.constEnd()) { //! [6] QSet<QString> set; ... -foreach (QString value, set) +foreach (const QString &value, set) qDebug() << value; //! [6] diff --git a/doc/src/snippets/code/doc_src_qt4-tulip.qdoc b/doc/src/snippets/code/doc_src_qt4-tulip.qdoc index 3d88a0d..f29d3ba 100644 --- a/doc/src/snippets/code/doc_src_qt4-tulip.qdoc +++ b/doc/src/snippets/code/doc_src_qt4-tulip.qdoc @@ -47,7 +47,7 @@ foreach (variable, container) //! [1] QList<QString> list; ... -foreach (QString str, list) +foreach (const QString &str, list) cout << str.ascii() << endl; //! [1] diff --git a/doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp b/doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp index 2e64505..fb62347 100644 --- a/doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp +++ b/doc/src/snippets/code/src_corelib_kernel_qcoreapplication.cpp @@ -51,7 +51,7 @@ connect(quitButton, SIGNAL(clicked()), &app, SLOT(quit())); //! [2] -foreach (QString path, app.libraryPaths()) +foreach (const QString &path, app.libraryPaths()) do_something(path); //! [2] diff --git a/doc/src/snippets/code/src_gui_kernel_qapplication.cpp b/doc/src/snippets/code/src_gui_kernel_qapplication.cpp index c93a25c..766b249 100644 --- a/doc/src/snippets/code/src_gui_kernel_qapplication.cpp +++ b/doc/src/snippets/code/src_gui_kernel_qapplication.cpp @@ -158,13 +158,13 @@ appname -session id //! [10] -foreach (QString command, mySession.restartCommand()) +foreach (const QString &command, mySession.restartCommand()) do_something(command); //! [10] //! [11] -foreach (QString command, mySession.discardCommand()) +foreach (const QString &command, mySession.discardCommand()) do_something(command); //! [11] diff --git a/doc/src/snippets/code/src_network_kernel_qhostinfo.cpp b/doc/src/snippets/code/src_network_kernel_qhostinfo.cpp index 3871289..99deb20 100644 --- a/doc/src/snippets/code/src_network_kernel_qhostinfo.cpp +++ b/doc/src/snippets/code/src_network_kernel_qhostinfo.cpp @@ -68,7 +68,7 @@ void MyWidget::lookedUp(const QHostInfo &host) return; } - foreach (QHostAddress address, host.addresses()) + foreach (const QHostAddress &address, host.addresses()) qDebug() << "Found address:" << address.toString(); } //! [3] diff --git a/doc/src/snippets/code/src_network_ssl_qsslcertificate.cpp b/doc/src/snippets/code/src_network_ssl_qsslcertificate.cpp index 5c9421f..937dbb9 100644 --- a/doc/src/snippets/code/src_network_ssl_qsslcertificate.cpp +++ b/doc/src/snippets/code/src_network_ssl_qsslcertificate.cpp @@ -39,7 +39,7 @@ ****************************************************************************/ //! [0] -foreach (QSslCertificate cert, QSslCertificate::fromPath("C:/ssl/certificate.*.pem", QSsl::Pem, +foreach (const QSslCertificate &cert, QSslCertificate::fromPath("C:/ssl/certificate.*.pem", QSsl::Pem, QRegExp::Wildcard)) { qDebug() << cert.issuerInfo(QSslCertificate::Organization); } diff --git a/doc/src/snippets/droparea.cpp b/doc/src/snippets/droparea.cpp index bbcf82d..bb49dd7 100644 --- a/doc/src/snippets/droparea.cpp +++ b/doc/src/snippets/droparea.cpp @@ -130,7 +130,7 @@ QPixmap DropArea::extractPixmap(const QByteArray &data, const QString &format) QList<QByteArray> imageFormats = QImageReader::supportedImageFormats(); QPixmap pixmap; - foreach (QByteArray imageFormat, imageFormats) { + foreach (const QByteArray &imageFormat, imageFormats) { if (format.mid(6) == QString(imageFormat)) { pixmap.loadFromData(data, imageFormat); break; diff --git a/doc/src/snippets/picture/picture.cpp b/doc/src/snippets/picture/picture.cpp index 0c5712a..5283978 100644 --- a/doc/src/snippets/picture/picture.cpp +++ b/doc/src/snippets/picture/picture.cpp @@ -76,7 +76,7 @@ int main() // FORMATS //! [2] QStringList list = QPicture::inputFormatList(); - foreach (QString string, list) + foreach (const QString &string, list) myProcessing(string); //! [2] } @@ -85,7 +85,7 @@ int main() // OUTPUT //! [3] QStringList list = QPicture::outputFormatList(); - foreach (QString string, list) + foreach (const QString &string, list) myProcessing(string); //! [3] } diff --git a/doc/src/snippets/qfontdatabase/main.cpp b/doc/src/snippets/qfontdatabase/main.cpp index 7f939de..1b8ff42 100644 --- a/doc/src/snippets/qfontdatabase/main.cpp +++ b/doc/src/snippets/qfontdatabase/main.cpp @@ -50,11 +50,11 @@ int main(int argc, char **argv) fontTree.setColumnCount(2); fontTree.setHeaderLabels(QStringList() << "Font" << "Smooth Sizes"); - foreach (QString family, database.families()) { + foreach (const QString &family, database.families()) { QTreeWidgetItem *familyItem = new QTreeWidgetItem(&fontTree); familyItem->setText(0, family); - foreach (QString style, database.styles(family)) { + foreach (const QString &style, database.styles(family)) { QTreeWidgetItem *styleItem = new QTreeWidgetItem(familyItem); styleItem->setText(0, style); diff --git a/doc/src/snippets/qlistview-dnd/model.cpp b/doc/src/snippets/qlistview-dnd/model.cpp index d310c03..bca71ee 100644 --- a/doc/src/snippets/qlistview-dnd/model.cpp +++ b/doc/src/snippets/qlistview-dnd/model.cpp @@ -109,7 +109,7 @@ bool DragDropListModel::dropMimeData(const QMimeData *data, //! [6] insertRows(beginRow, rows, QModelIndex()); - foreach (QString text, newItems) { + foreach (const QString &text, newItems) { QModelIndex idx = index(beginRow, 0, QModelIndex()); setData(idx, text); beginRow++; @@ -139,7 +139,7 @@ QMimeData *DragDropListModel::mimeData(const QModelIndexList &indexes) const QDataStream stream(&encodedData, QIODevice::WriteOnly); - foreach (QModelIndex index, indexes) { + foreach (const QModelIndex &index, indexes) { if (index.isValid()) { QString text = data(index, Qt::DisplayRole).toString(); stream << text; diff --git a/doc/src/snippets/qstringlist/main.cpp b/doc/src/snippets/qstringlist/main.cpp index 76785f1..9ada319 100644 --- a/doc/src/snippets/qstringlist/main.cpp +++ b/doc/src/snippets/qstringlist/main.cpp @@ -118,7 +118,7 @@ Widget::Widget(QWidget *parent) result.clear(); //! [12] - foreach (QString str, list) { + foreach (const QString &str, list) { if (str.contains("Bill")) result += str; } diff --git a/doc/src/snippets/qtreeview-dnd/dragdropmodel.cpp b/doc/src/snippets/qtreeview-dnd/dragdropmodel.cpp index 2d01240..620a716 100644 --- a/doc/src/snippets/qtreeview-dnd/dragdropmodel.cpp +++ b/doc/src/snippets/qtreeview-dnd/dragdropmodel.cpp @@ -123,7 +123,7 @@ QMimeData *DragDropModel::mimeData(const QModelIndexList &indexes) const QDataStream stream(&encodedData, QIODevice::WriteOnly); - foreach (QModelIndex index, indexes) { + foreach (const QModelIndex &index, indexes) { if (index.isValid()) { QString text = data(index, Qt::DisplayRole).toString(); stream << index.internalId() << index.row() << index.column() << text; diff --git a/doc/src/snippets/widgets-tutorial/nestedlayouts/main.cpp b/doc/src/snippets/widgets-tutorial/nestedlayouts/main.cpp index 6a49be8..35d2fa7 100644 --- a/doc/src/snippets/widgets-tutorial/nestedlayouts/main.cpp +++ b/doc/src/snippets/widgets-tutorial/nestedlayouts/main.cpp @@ -72,9 +72,9 @@ int main(int argc, char *argv[]) << (QStringList() << "David Bradley" << "42") << (QStringList() << "Knut Walters" << "25") << (QStringList() << "Andrea Jones" << "34"); - foreach (QStringList row, rows) { + foreach (const QStringList &row, rows) { QList<QStandardItem *> items; - foreach (QString text, row) + foreach (const QString &text, row) items.append(new QStandardItem(text)); model.appendRow(items); } |