summaryrefslogtreecommitdiffstats
path: root/doc/src/snippets
diff options
context:
space:
mode:
authorAlberto Mardegan <mardy@users.sourceforge.net>2011-04-04 10:28:09 (GMT)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2011-04-04 10:44:22 (GMT)
commit3290e4c1956bc6df63af669523391565c67e8c42 (patch)
treeb6efbe424cd1a50097193dbad363f5cd1b7a2188 /doc/src/snippets
parent0cf75b4dd1cc25694de8ece4c25ecb97a3969a54 (diff)
downloadQt-3290e4c1956bc6df63af669523391565c67e8c42.zip
Qt-3290e4c1956bc6df63af669523391565c67e8c42.tar.gz
Qt-3290e4c1956bc6df63af669523391565c67e8c42.tar.bz2
Add branch prediction macros
This adds support for Q_LIKELY and Q_UNLIKELY macros which instruct the compiler on which branch of an "if" statement is more likely to happen. The current patch only supports GCC's __builtin_expect(). Merge-request: 2580 Reviewed-by: ossi
Diffstat (limited to 'doc/src/snippets')
-rw-r--r--doc/src/snippets/code/src_corelib_global_qglobal.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/doc/src/snippets/code/src_corelib_global_qglobal.cpp b/doc/src/snippets/code/src_corelib_global_qglobal.cpp
index 0b54cef..c79a714 100644
--- a/doc/src/snippets/code/src_corelib_global_qglobal.cpp
+++ b/doc/src/snippets/code/src_corelib_global_qglobal.cpp
@@ -531,3 +531,27 @@ class MyClass : public QObject
//! [47]
CApaApplication *myApplicationFactory();
//! [47]
+
+//! [qlikely]
+ // the condition inside the "if" will be successful most of the times
+ for (int i = 1; i <= 365; i++) {
+ if (Q_LIKELY(isWorkingDay(i))) {
+ ...
+ }
+ ...
+ }
+//! [qlikely]
+
+//! [qunlikely]
+bool readConfiguration(const QFile &file)
+{
+ // We expect to be asked to read an existing file
+ if (Q_UNLIKELY(!file.exists())) {
+ qWarning() << "File not found";
+ return false;
+ }
+
+ ...
+ return true;
+}
+//! [qunlikely]