From 7afc73d1a894c2395ec8ba099adf4fb49ce561e3 Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Tue, 11 Jan 2011 13:26:18 +0100 Subject: deal with utcOffset in a correct way like how we do that for ISO format Reviewed-by: ddenis Merge-request: 2536 Reviewed-by: Olivier Goffart --- src/corelib/tools/qdatetime.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index 6a20c7a..9f71457 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -3426,8 +3426,9 @@ QDateTime QDateTime::fromString(const QString& s, Qt::DateFormat f) QString tz = parts.at(5); if (!tz.startsWith(QLatin1String("GMT"), Qt::CaseInsensitive)) return QDateTime(); - int tzoffset = 0; + QDateTime dt(date, time, Qt::UTC); if (tz.length() > 3) { + int tzoffset = 0; QChar sign = tz.at(3); if ((sign != QLatin1Char('+')) && (sign != QLatin1Char('-'))) { @@ -3442,8 +3443,9 @@ QDateTime QDateTime::fromString(const QString& s, Qt::DateFormat f) tzoffset = (tzhour*60 + tzminute) * 60; if (sign == QLatin1Char('-')) tzoffset = -tzoffset; + dt.setUtcOffset(tzoffset); } - return QDateTime(date, time, Qt::UTC).addSecs(-tzoffset).toLocalTime(); + return dt.toLocalTime(); } #endif //QT_NO_TEXTDATE } -- cgit v0.12 From 54db2506e8f228487c109ec7efc7a2a9681e9087 Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Tue, 11 Jan 2011 13:26:19 +0100 Subject: fix/stabilizate the year sign change test this test might fail for the Qt::LocalTime spec in some cases Merge-request: 2536 Reviewed-by: Olivier Goffart --- tests/auto/qdatetime/tst_qdatetime.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/auto/qdatetime/tst_qdatetime.cpp b/tests/auto/qdatetime/tst_qdatetime.cpp index 1841487..851e1ee 100644 --- a/tests/auto/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/qdatetime/tst_qdatetime.cpp @@ -705,12 +705,12 @@ void tst_QDateTime::addSecs_data() } // Year sign change - QTest::newRow("toNegative") << QDateTime(QDate(1, 1, 1), QTime(0, 0, 0)) + QTest::newRow("toNegative") << QDateTime(QDate(1, 1, 1), QTime(0, 0, 0), Qt::UTC) << -1 - << QDateTime(QDate(-1, 12, 31), QTime(23, 59, 59)); - QTest::newRow("toPositive") << QDateTime(QDate(-1, 12, 31), QTime(23, 59, 59)) + << QDateTime(QDate(-1, 12, 31), QTime(23, 59, 59), Qt::UTC); + QTest::newRow("toPositive") << QDateTime(QDate(-1, 12, 31), QTime(23, 59, 59), Qt::UTC) << 1 - << QDateTime(QDate(1, 1, 1), QTime(0, 0, 0)); + << QDateTime(QDate(1, 1, 1), QTime(0, 0, 0), Qt::UTC); // Gregorian/Julian switchover QTest::newRow("toGregorian") << QDateTime(QDate(1582, 10, 4), QTime(23, 59, 59)) -- cgit v0.12 From 76a0c085c8fc6e5f2a46b186a4a1c83e3713bd76 Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Tue, 11 Jan 2011 14:33:33 +0300 Subject: make the modifySemaphore() signal-safe on linux as POSIX man says, if semop() is interrupted by a signal, it shall return -1 and set errno to EINTR. in qcore_unix_p.h, we have EINTR_LOOP helper macro exactly for such cases ;) Task-number: QTBUG-14434 Merge-request: 998 Reviewed-by: Olivier Goffart --- src/corelib/kernel/qsystemsemaphore_unix.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/corelib/kernel/qsystemsemaphore_unix.cpp b/src/corelib/kernel/qsystemsemaphore_unix.cpp index 07e3618..9d0c0b9 100644 --- a/src/corelib/kernel/qsystemsemaphore_unix.cpp +++ b/src/corelib/kernel/qsystemsemaphore_unix.cpp @@ -56,6 +56,8 @@ #include +#include "private/qcore_unix_p.h" + // OpenBSD 4.2 doesn't define EIDRM, see BUGS section: // http://www.openbsd.org/cgi-bin/man.cgi?query=semop&manpath=OpenBSD+4.2 #if defined(Q_OS_OPENBSD) && !defined(EIDRM) @@ -218,7 +220,10 @@ bool QSystemSemaphorePrivate::modifySemaphore(int count) operation.sem_num = 0; operation.sem_op = count; operation.sem_flg = SEM_UNDO; - if (-1 == semop(semaphore, &operation, 1)) { + + register int res; + EINTR_LOOP(res, semop(semaphore, &operation, 1)); + if (-1 == res) { // If the semaphore was removed be nice and create it and then modifySemaphore again if (errno == EINVAL || errno == EIDRM) { semaphore = -1; -- cgit v0.12 From 3bd2b098888432aa29cc085759963dbb7e009ecf Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Tue, 11 Jan 2011 14:35:08 +0300 Subject: remove unused header include sysV shm isn't used in QSystemSemaphore Merge-request: 998 Reviewed-by: Olivier Goffart --- src/corelib/kernel/qsystemsemaphore_unix.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/corelib/kernel/qsystemsemaphore_unix.cpp b/src/corelib/kernel/qsystemsemaphore_unix.cpp index 9d0c0b9..445fef8 100644 --- a/src/corelib/kernel/qsystemsemaphore_unix.cpp +++ b/src/corelib/kernel/qsystemsemaphore_unix.cpp @@ -50,11 +50,9 @@ #include #include +#include #include #include -#include - -#include #include "private/qcore_unix_p.h" -- cgit v0.12 From 62a681d116154235325c8b13f6df0042d81851ee Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Tue, 11 Jan 2011 13:58:19 +0100 Subject: fix warning "'SeedStorage* randTLS()' defined but not used" by setting the proper macro-guards; regroup macro-guards for better readability (superfluous change, I know); fix typos in the comments was not splited into two commits to make it more clear why and how that warning is fixed now Merge-request: 955 Reviewed-by: Olivier Goffart --- src/corelib/global/qglobal.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 9b597f6..5d079d0 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -2589,7 +2589,7 @@ bool qputenv(const char *varName, const QByteArray& value) #endif } -#if (defined(Q_OS_UNIX) || defined(Q_OS_WIN)) && !defined(QT_NO_THREAD) +#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN) && !defined(QT_NO_THREAD) # if defined(Q_OS_INTEGRITY) && defined(__GHS_VERSION_NUMBER) && (__GHS_VERSION_NUMBER < 500) // older versions of INTEGRITY used a long instead of a uint for the seed. @@ -2620,7 +2620,7 @@ Q_GLOBAL_STATIC(SeedStorage, randTLS) // Thread Local Storage for seed value */ void qsrand(uint seed) { -#if defined(Q_OS_UNIX) && !defined(QT_NO_THREAD) && !defined(Q_OS_SYMBIAN) +#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN) && !defined(QT_NO_THREAD) SeedStorage *seedStorage = randTLS(); if (seedStorage) { SeedStorageType *pseed = seedStorage->localData(); @@ -2628,10 +2628,10 @@ void qsrand(uint seed) seedStorage->setLocalData(pseed = new SeedStorageType); *pseed = seed; } else { - //golbal static seed storage should always exist, + //global static seed storage should always exist, //except after being deleted by QGlobalStaticDeleter. //But since it still can be called from destructor of another - //global static object, fallback to sqrand(seed) + //global static object, fallback to srand(seed) srand(seed); } #else @@ -2659,7 +2659,7 @@ void qsrand(uint seed) */ int qrand() { -#if defined(Q_OS_UNIX) && !defined(QT_NO_THREAD) && !defined(Q_OS_SYMBIAN) +#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN) && !defined(QT_NO_THREAD) SeedStorage *seedStorage = randTLS(); if (seedStorage) { SeedStorageType *pseed = seedStorage->localData(); @@ -2669,10 +2669,10 @@ int qrand() } return rand_r(pseed); } else { - //golbal static seed storage should always exist, + //global static seed storage should always exist, //except after being deleted by QGlobalStaticDeleter. //But since it still can be called from destructor of another - //global static object, fallback to qrand() + //global static object, fallback to rand() return rand(); } #else -- cgit v0.12 From 2da612ca235fe65a7bfc7a7515fec15eaf1134e7 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Tue, 11 Jan 2011 13:58:19 +0100 Subject: fix warning "missing braces around initializer for 'in_addr::'" v.s_addr = 0; does the same Merge-request: 955 Reviewed-by: Olivier Goffart --- src/network/socket/qnativesocketengine_win.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/network/socket/qnativesocketengine_win.cpp b/src/network/socket/qnativesocketengine_win.cpp index dbf443e..eec78c4 100644 --- a/src/network/socket/qnativesocketengine_win.cpp +++ b/src/network/socket/qnativesocketengine_win.cpp @@ -918,7 +918,8 @@ QNetworkInterface QNativeSocketEnginePrivate::nativeMulticastInterface() const } #endif - struct in_addr v = { 0 }; + struct in_addr v; + v.s_addr = 0; QT_SOCKOPTLEN_T sizeofv = sizeof(v); if (::getsockopt(socketDescriptor, IPPROTO_IP, IP_MULTICAST_IF, (char *) &v, &sizeofv) == -1) return QNetworkInterface(); -- cgit v0.12 From f30e617950de2882434bfa5707bd8cdb91102c97 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Tue, 11 Jan 2011 13:58:20 +0100 Subject: fix warning "comparison between signed and unsigned integer expressions" sizeof produces signed int result; QT_SOCKOPTLEN_T is int Merge-request: 955 Reviewed-by: Olivier Goffart --- src/network/socket/qnativesocketengine_win.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/socket/qnativesocketengine_win.cpp b/src/network/socket/qnativesocketengine_win.cpp index eec78c4..4c290f7 100644 --- a/src/network/socket/qnativesocketengine_win.cpp +++ b/src/network/socket/qnativesocketengine_win.cpp @@ -923,7 +923,7 @@ QNetworkInterface QNativeSocketEnginePrivate::nativeMulticastInterface() const QT_SOCKOPTLEN_T sizeofv = sizeof(v); if (::getsockopt(socketDescriptor, IPPROTO_IP, IP_MULTICAST_IF, (char *) &v, &sizeofv) == -1) return QNetworkInterface(); - if (v.s_addr != 0 && sizeofv >= sizeof(v)) { + if (v.s_addr != 0 && sizeofv >= QT_SOCKOPTLEN_T(sizeof(v))) { QHostAddress ipv4(ntohl(v.s_addr)); QList ifaces = QNetworkInterface::allInterfaces(); for (int i = 0; i < ifaces.count(); ++i) { -- cgit v0.12 From ebf988356f9b8aee4968250dc1f21e841c6e5dbf Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Tue, 11 Jan 2011 13:58:21 +0100 Subject: fix another "comparison between signed and unsigned integer expressions" on win, when used in FD_SET, FD_ISSET, etc., socketDescriptor assumed to be SOCKET which is unsigned int Merge-request: 955 Reviewed-by: Olivier Goffart --- src/network/socket/qnativesocketengine_win.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/network/socket/qnativesocketengine_win.cpp b/src/network/socket/qnativesocketengine_win.cpp index 4c290f7..f6ebcfb 100644 --- a/src/network/socket/qnativesocketengine_win.cpp +++ b/src/network/socket/qnativesocketengine_win.cpp @@ -1038,7 +1038,7 @@ bool QNativeSocketEnginePrivate::nativeHasPendingDatagrams() const bool result = false; fd_set readS; FD_ZERO(&readS); - FD_SET(socketDescriptor, &readS); + FD_SET((SOCKET)socketDescriptor, &readS); timeval timeout; timeout.tv_sec = 0; timeout.tv_usec = 5000; @@ -1333,7 +1333,7 @@ int QNativeSocketEnginePrivate::nativeSelect(int timeout, bool selectForRead) co memset(&fds, 0, sizeof(fd_set)); fds.fd_count = 1; - fds.fd_array[0] = socketDescriptor; + fds.fd_array[0] = (SOCKET)socketDescriptor; struct timeval tv; tv.tv_sec = timeout / 1000; @@ -1347,12 +1347,12 @@ int QNativeSocketEnginePrivate::nativeSelect(int timeout, bool selectForRead) co // Windows needs this to report errors when connecting a socket ... fd_set fdexception; FD_ZERO(&fdexception); - FD_SET(socketDescriptor, &fdexception); + FD_SET((SOCKET)socketDescriptor, &fdexception); ret = select(0, 0, &fds, &fdexception, timeout < 0 ? 0 : &tv); // ... but if it is actually set, pretend it did not happen - if (ret > 0 && FD_ISSET(socketDescriptor, &fdexception)) + if (ret > 0 && FD_ISSET((SOCKET)socketDescriptor, &fdexception)) ret--; } @@ -1379,16 +1379,16 @@ int QNativeSocketEnginePrivate::nativeSelect(int timeout, memset(&fdread, 0, sizeof(fd_set)); if (checkRead) { fdread.fd_count = 1; - fdread.fd_array[0] = socketDescriptor; + fdread.fd_array[0] = (SOCKET)socketDescriptor; } memset(&fdwrite, 0, sizeof(fd_set)); FD_ZERO(&fdexception); if (checkWrite) { fdwrite.fd_count = 1; - fdwrite.fd_array[0] = socketDescriptor; + fdwrite.fd_array[0] = (SOCKET)socketDescriptor; // Windows needs this to report errors when connecting a socket - FD_SET(socketDescriptor, &fdexception); + FD_SET((SOCKET)socketDescriptor, &fdexception); } struct timeval tv; @@ -1402,7 +1402,7 @@ int QNativeSocketEnginePrivate::nativeSelect(int timeout, #endif //... but if it is actually set, pretend it did not happen - if (ret > 0 && FD_ISSET(socketDescriptor, &fdexception)) + if (ret > 0 && FD_ISSET((SOCKET)socketDescriptor, &fdexception)) ret--; if (readEnabled) @@ -1411,8 +1411,8 @@ int QNativeSocketEnginePrivate::nativeSelect(int timeout, if (ret <= 0) return ret; - *selectForRead = FD_ISSET(socketDescriptor, &fdread); - *selectForWrite = FD_ISSET(socketDescriptor, &fdwrite); + *selectForRead = FD_ISSET((SOCKET)socketDescriptor, &fdread); + *selectForWrite = FD_ISSET((SOCKET)socketDescriptor, &fdwrite); return ret; } -- cgit v0.12 From 5819280b42c32233e9db0981f143704995957ef4 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Tue, 11 Jan 2011 13:58:22 +0100 Subject: fix 'QChar::QChar(char)' is deprecated Merge-request: 955 Reviewed-by: Olivier Goffart --- src/gui/dialogs/qfiledialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/dialogs/qfiledialog.cpp b/src/gui/dialogs/qfiledialog.cpp index 9509330..f7fa705 100644 --- a/src/gui/dialogs/qfiledialog.cpp +++ b/src/gui/dialogs/qfiledialog.cpp @@ -3311,7 +3311,7 @@ QString QFSCompleter::pathFromIndex(const QModelIndex &index) const if (currentLocation == QDir::separator()) return path.mid(currentLocation.length()); #endif - if (currentLocation.endsWith('/')) + if (currentLocation.endsWith(QLatin1Char('/'))) return path.mid(currentLocation.length()); else return path.mid(currentLocation.length()+1); -- cgit v0.12 From 540fbb2aec0e9187acd75598a050edf8929e1d68 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Tue, 11 Jan 2011 13:58:23 +0100 Subject: fix two more "comparison between signed and unsigned integer expressions" warnings SQLLEN is unnecessarily an unsigned int Merge-request: 955 Reviewed-by: Olivier Goffart --- src/sql/drivers/odbc/qsql_odbc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sql/drivers/odbc/qsql_odbc.cpp b/src/sql/drivers/odbc/qsql_odbc.cpp index 3e77779..445a3ac 100644 --- a/src/sql/drivers/odbc/qsql_odbc.cpp +++ b/src/sql/drivers/odbc/qsql_odbc.cpp @@ -391,7 +391,7 @@ static QString qGetStringData(SQLHANDLE hStmt, int column, int colSize, bool uni // colSize-1: remove 0 termination when there is more data to fetch int rSize = (r == SQL_SUCCESS_WITH_INFO) ? colSize : lengthIndicator/sizeof(SQLTCHAR); fieldVal += fromSQLTCHAR(buf, rSize); - if (lengthIndicator < (unsigned int)colSize*sizeof(SQLTCHAR)) { + if (lengthIndicator < SQLLEN(colSize*sizeof(SQLTCHAR))) { // workaround for Drivermanagers that don't return SQL_NO_DATA break; } @@ -432,7 +432,7 @@ static QString qGetStringData(SQLHANDLE hStmt, int column, int colSize, bool uni // colSize-1: remove 0 termination when there is more data to fetch int rSize = (r == SQL_SUCCESS_WITH_INFO) ? colSize : lengthIndicator; fieldVal += QString::fromUtf8((const char *)buf.constData(), rSize); - if (lengthIndicator < (unsigned int)colSize) { + if (lengthIndicator < SQLLEN(colSize)) { // workaround for Drivermanagers that don't return SQL_NO_DATA break; } -- cgit v0.12 From b500b9f35fbeaa5f0fe8bfaf7b225518bf6e636f Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Tue, 11 Jan 2011 14:12:01 +0100 Subject: use qBinaryFind instead of bsearch depending on platform, qBinaryFind might be up to 3 times faster than bsearch or a bit bit slower at the worst case; so why don't simply use qBinaryFind instead of bsearch and be an optimist? ;) also we know that all color names are in the lower case already and thus we can avoid lowercasing of them again and again, and again; the name to find needs to be lowercased separately instead. some color-by-name-lookup numbers: before: 0.000737 msecs per iteration (total: 3,684, iterations: 5000000) after: 0.000154 msecs per iteration (total: 771, iterations: 5000000) Merge-request: 906 Reviewed-by: Olivier Goffart --- src/gui/image/qxpmhandler.cpp | 32 +++++++------------------------- src/gui/painting/qcolor_p.cpp | 36 ++++++++---------------------------- 2 files changed, 15 insertions(+), 53 deletions(-) diff --git a/src/gui/image/qxpmhandler.cpp b/src/gui/image/qxpmhandler.cpp index 453100c..6afb305 100644 --- a/src/gui/image/qxpmhandler.cpp +++ b/src/gui/image/qxpmhandler.cpp @@ -54,12 +54,6 @@ #include "qplatformdefs.h" #endif -#include - -#if defined(Q_OS_WINCE) -#include "qguifunctions_wince.h" -#endif - QT_BEGIN_NAMESPACE static quint64 xpmHash(const QString &str) @@ -751,27 +745,15 @@ static const struct XPMRGBData { { QRGB(139,139, 0), "yellow4" }, { QRGB(154,205, 50), "yellowgreen" } }; -#if defined(Q_C_CALLBACKS) -extern "C" { -#endif -static int rgb_cmp(const void *d1, const void *d2) -{ - return qstricmp(((XPMRGBData *)d1)->name, ((XPMRGBData *)d2)->name); -} -#if defined(Q_C_CALLBACKS) -} -#endif +inline bool operator<(const char *name, const XPMRGBData &data) +{ return qstrcmp(name, data.name) < 0; } +inline bool operator<(const XPMRGBData &data, const char *name) +{ return qstrcmp(data.name, name) < 0; } -static bool qt_get_named_xpm_rgb(const char *name_no_space, QRgb *rgb) +static inline bool qt_get_named_xpm_rgb(const char *name_no_space, QRgb *rgb) { - XPMRGBData x; - x.name = name_no_space; - // Function bsearch() is supposed to be - // void *bsearch(const void *key, const void *base, ... - // So why (char*)? Are there broken bsearch() declarations out there? - XPMRGBData *r = (XPMRGBData *)bsearch((char *)&x, (char *)xpmRgbTbl, xpmRgbTblSize, - sizeof(XPMRGBData), rgb_cmp); - if (r) { + const XPMRGBData *r = qBinaryFind(xpmRgbTbl, xpmRgbTbl + xpmRgbTblSize, name_no_space); + if (r != xpmRgbTbl + xpmRgbTblSize) { *rgb = r->value; return true; } else { diff --git a/src/gui/painting/qcolor_p.cpp b/src/gui/painting/qcolor_p.cpp index b1adf9f..d66990d 100644 --- a/src/gui/painting/qcolor_p.cpp +++ b/src/gui/painting/qcolor_p.cpp @@ -49,9 +49,6 @@ #include "qrgb.h" #include "qstringlist.h" -#if defined(Q_WS_WINCE) -#include "qguifunctions_wince.h" -#endif QT_BEGIN_NAMESPACE static inline int h2i(char hex) @@ -290,33 +287,16 @@ static const int rgbTblSize = sizeof(rgbTbl) / sizeof(RGBData); #undef rgb -QT_BEGIN_INCLUDE_NAMESPACE -#include -QT_END_INCLUDE_NAMESPACE - -#if defined(Q_C_CALLBACKS) -extern "C" { -#endif - -#ifdef Q_OS_WINCE -static int __cdecl rgb_cmp(const void *d1, const void *d2) -#else -static int rgb_cmp(const void *d1, const void *d2) -#endif -{ - return qstricmp(((RGBData *)d1)->name, ((RGBData *)d2)->name); -} - -#if defined(Q_C_CALLBACKS) -} -#endif +inline bool operator<(const char *name, const RGBData &data) +{ return qstrcmp(name, data.name) < 0; } +inline bool operator<(const RGBData &data, const char *name) +{ return qstrcmp(data.name, name) < 0; } -static bool get_named_rgb(const char *name, QRgb *rgb) +static bool get_named_rgb(const char *name_no_space, QRgb *rgb) { - RGBData x; - x.name = name; - RGBData *r = (RGBData*)bsearch(&x, rgbTbl, rgbTblSize, sizeof(RGBData), rgb_cmp); - if (r) { + QByteArray name = QByteArray(name_no_space).toLower(); + const RGBData *r = qBinaryFind(rgbTbl, rgbTbl + rgbTblSize, name.constData()); + if (r != rgbTbl + rgbTblSize) { *rgb = r->value; return true; } -- cgit v0.12 From 3e865c9f80bd3666673158e8a1664e7405fe9364 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Tue, 11 Jan 2011 14:12:02 +0100 Subject: use qBinaryFind instead of bsearch Merge-request: 906 Reviewed-by: Olivier Goffart --- src/plugins/codecs/kr/qeuckrcodec.cpp | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/plugins/codecs/kr/qeuckrcodec.cpp b/src/plugins/codecs/kr/qeuckrcodec.cpp index 1246164..0fbd2a0 100644 --- a/src/plugins/codecs/kr/qeuckrcodec.cpp +++ b/src/plugins/codecs/kr/qeuckrcodec.cpp @@ -67,11 +67,6 @@ #include "qeuckrcodec.h" #include "cp949codetbl.h" -#include - -#if defined(Q_OS_WINCE) -# include -#endif QT_BEGIN_NAMESPACE @@ -3402,11 +3397,6 @@ QByteArray QCP949Codec::_name() return "cp949"; } -int compare_ushort(const void *a, const void *b) -{ - return *(unsigned short *)a - *(unsigned short *)b; -} - /*! \reimp */ @@ -3434,10 +3424,8 @@ QByteArray QCP949Codec::convertFromUnicode(const QChar *uc, int len, ConverterSt *cursor++ = (j >> 8) | 0x80; *cursor++ = (j & 0xff) | 0x80; } else { - unsigned short *ptr = (unsigned short *)bsearch(&ch, cp949_icode_to_unicode, 8822, - sizeof(unsigned short), compare_ushort); - - if(!ptr) { + const unsigned short *ptr = qBinaryFind(cp949_icode_to_unicode, cp949_icode_to_unicode + 8822, ch); + if (ptr == cp949_icode_to_unicode + 8822) { // Error *cursor++ = replacement; ++invalid; -- cgit v0.12 From 924238ae5a3c784d907cf6f95df8eb7c3e568970 Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Tue, 11 Jan 2011 16:31:05 +0300 Subject: QProcessManager: minor optimization QHash is slightly faster than QMap and should be preferred where the key order has no meaning; take() is faster than value() + remove() Reviewed-by: Olivier Goffart Merge-request: 1017 --- src/corelib/io/qprocess_unix.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 299280e..d4cf3f5 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -95,7 +95,7 @@ QT_END_NAMESPACE #include #include #include -#include +#include #include #include #include @@ -163,7 +163,7 @@ public: private: QMutex mutex; - QMap children; + QHash children; }; @@ -281,7 +281,7 @@ void QProcessManager::catchDeadChildren() // try to catch all children whose pid we have registered, and whose // deathPipe is still valid (i.e, we have not already notified it). - QMap::Iterator it = children.begin(); + QHash::Iterator it = children.begin(); while (it != children.end()) { // notify all children that they may have died. they need to run // waitpid() in their own thread. @@ -320,15 +320,11 @@ void QProcessManager::remove(QProcess *process) QMutexLocker locker(&mutex); int serial = process->d_func()->serial; - QProcessInfo *info = children.value(serial); - if (!info) - return; - + QProcessInfo *info = children.take(serial); #if defined (QPROCESS_DEBUG) - qDebug() << "QProcessManager::remove() removing pid" << info->pid << "process" << info->process; + if (info) + qDebug() << "QProcessManager::remove() removing pid" << info->pid << "process" << info->process; #endif - - children.remove(serial); delete info; } -- cgit v0.12