summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndreas Kling <andreas.kling@nokia.com>2010-06-04 18:47:46 (GMT)
committerAndreas Kling <andreas.kling@nokia.com>2010-06-04 20:14:05 (GMT)
commit09c6a81109d3978c1583c556202c01c1e774f11f (patch)
treea8bacfb704af35ef2b80459f19ce9e5bdcbcb238 /src
parent2b4d2fd1ada524f4780dd7633ca34bc72d823ff1 (diff)
downloadQt-09c6a81109d3978c1583c556202c01c1e774f11f.zip
Qt-09c6a81109d3978c1583c556202c01c1e774f11f.tar.gz
Qt-09c6a81109d3978c1583c556202c01c1e774f11f.tar.bz2
Make qbswap() use glibc's fast bswap_*() functions if available.
Reviewed-by: Thiago Macieira
Diffstat (limited to 'src')
-rw-r--r--src/corelib/global/qendian.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/corelib/global/qendian.h b/src/corelib/global/qendian.h
index 107854c..353e8b9 100644
--- a/src/corelib/global/qendian.h
+++ b/src/corelib/global/qendian.h
@@ -42,6 +42,16 @@
#ifndef QENDIAN_H
#define QENDIAN_H
+#ifdef Q_OS_LINUX
+QT_BEGIN_INCLUDE_NAMESPACE
+# include <features.h>
+QT_END_INCLUDE_NAMESPACE
+#endif
+
+#ifdef __GLIBC__
+#include <byteswap.h>
+#endif
+
#include <QtCore/qglobal.h>
QT_BEGIN_HEADER
@@ -264,6 +274,21 @@ template <> inline qint16 qFromBigEndian<qint16>(const uchar *src)
* and it is therefore a bit more convenient and in most cases more efficient.
*/
template <typename T> T qbswap(T source);
+
+#ifdef __GLIBC__
+template <> inline quint64 qbswap<quint64>(quint64 source)
+{
+ return bswap_64(source);
+}
+template <> inline quint32 qbswap<quint32>(quint32 source)
+{
+ return bswap_32(source);
+}
+template <> inline quint16 qbswap<quint16>(quint16 source)
+{
+ return bswap_16(source);
+}
+#else
template <> inline quint64 qbswap<quint64>(quint64 source)
{
return 0
@@ -292,6 +317,7 @@ template <> inline quint16 qbswap<quint16>(quint16 source)
| ((source & 0x00ff) << 8)
| ((source & 0xff00) >> 8) );
}
+#endif // __GLIBC__
// signed specializations
template <> inline qint64 qbswap<qint64>(qint64 source)