From 884ea10d037d855b91ea5ef947b5c23d2f09aead Mon Sep 17 00:00:00 2001 From: Dirk Mueller Date: Wed, 17 Feb 2010 23:04:34 +0100 Subject: Fix undefined sequence point compiler warning level = ++level is not guaranteed to work, as the increment is not required to happen before the assignment. Change this code to be less obscure and use standard defined behavior. Merge-request: 471 Reviewed-by: Thiago Macieira --- src/gui/kernel/qsoftkeymanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/kernel/qsoftkeymanager.cpp b/src/gui/kernel/qsoftkeymanager.cpp index 6d108b0..d89276f 100644 --- a/src/gui/kernel/qsoftkeymanager.cpp +++ b/src/gui/kernel/qsoftkeymanager.cpp @@ -215,7 +215,7 @@ bool QSoftKeyManager::handleUpdateSoftKeys() if (source) { bool added = appendSoftkeys(*source, level); source = softkeySource(source, recursiveMerging); - level = added ? ++level : level; + level = added ? level + 1 : level; } } while (source); -- cgit v0.12 From cdf4701f442149546043b155cddcc53116875f1c Mon Sep 17 00:00:00 2001 From: Dirk Mueller Date: Wed, 17 Feb 2010 23:17:36 +0100 Subject: Fix s390(x) atomic ops related crashes The s390 implementation of the pointer related atomic ops never worked before, and the memory barrier was mixed up between the Acquire and the Relaxed variant. This fixes both. Merge-request: 2312 Reviewed-by: Thiago Macieira --- src/corelib/arch/qatomic_s390.h | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/corelib/arch/qatomic_s390.h b/src/corelib/arch/qatomic_s390.h index 21f5037..273c17b 100644 --- a/src/corelib/arch/qatomic_s390.h +++ b/src/corelib/arch/qatomic_s390.h @@ -366,11 +366,9 @@ template Q_INLINE_TEMPLATE T* QBasicAtomicPointer::fetchAndStoreRelaxed(T *newValue) { #ifndef __s390x__ - return (T*)__CS_OLD_LOOP(reinterpret_cast(_q_value), (int)newValue, "lr", - "", "bcr 15,0\n"); + return (T*)__CS_OLD_LOOP(&_q_value, (int)newValue, "lr", "", ""); #else - return (T*)__CSG_OLD_LOOP(reinterpret_cast(_q_value), (long)newValue, "lgr", - "", "bcr 15,0\n"); + return (T*)__CSG_OLD_LOOP(&_q_value, (long)newValue, "lgr", "", ""); #endif } @@ -378,9 +376,9 @@ template Q_INLINE_TEMPLATE T* QBasicAtomicPointer::fetchAndStoreAcquire(T *newValue) { #ifndef __s390x__ - return (T*)__CS_OLD_LOOP(reinterpret_cast(_q_value), (int)newValue, "lr", "", ""); + return (T*)__CS_OLD_LOOP(&_q_value, (int)newValue, "lr", "", "bcr 15,0 \n"); #else - return (T*)__CSG_OLD_LOOP(reinterpret_cast(_q_value), (long)newValue, "lgr", "", ""); + return (T*)__CSG_OLD_LOOP(&_q_value, (long)newValue, "lgr", "", "bcr 15,0 \n"); #endif } @@ -388,11 +386,9 @@ template Q_INLINE_TEMPLATE T* QBasicAtomicPointer::fetchAndStoreRelease(T *newValue) { #ifndef __s390x__ - return (T*)__CS_OLD_LOOP(reinterpret_cast(_q_value), (int)newValue, "lr", - "bcr 15,0 \n", ""); + return (T*)__CS_OLD_LOOP(&_q_value, (int)newValue, "lr", "bcr 15,0 \n", ""); #else - return (T*)__CSG_OLD_LOOP(reinterpret_cast(_q_value), (long)newValue, "lgr", - "bcr 15,0\n", ""); + return (T*)__CSG_OLD_LOOP(&_q_value, (long)newValue, "lgr", "bcr 15,0\n", ""); #endif } -- cgit v0.12 From c07f8354bec3c7b6d78f798589119ed0ab4f1332 Mon Sep 17 00:00:00 2001 From: ck Date: Fri, 12 Feb 2010 11:29:20 +0100 Subject: Help system: Handle all Clucene exceptions. Reviewed-by: kh1 --- .../lib/qhelpsearchindexwriter_clucene.cpp | 230 ++++++++++----------- 1 file changed, 112 insertions(+), 118 deletions(-) diff --git a/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp b/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp index e3cc2b0..2eeefb5 100644 --- a/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp +++ b/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp @@ -613,67 +613,69 @@ void QHelpSearchIndexWriter::optimizeIndex() void QHelpSearchIndexWriter::run() { - QMutexLocker mutexLocker(&mutex); +#if !defined(QT_NO_EXCEPTIONS) + try { +#endif + QMutexLocker mutexLocker(&mutex); - if (m_cancel) - return; + if (m_cancel) + return; - const bool reindex = this->m_reindex; - const QString collectionFile(this->m_collectionFile); + const bool reindex = this->m_reindex; + const QString collectionFile(this->m_collectionFile); - mutexLocker.unlock(); + mutexLocker.unlock(); - QHelpEngineCore engine(collectionFile, 0); - if (!engine.setupData()) - return; + QHelpEngineCore engine(collectionFile, 0); + if (!engine.setupData()) + return; - const QLatin1String key("CluceneIndexedNamespaces"); - if (reindex) - engine.setCustomValue(key, QLatin1String("")); - - QMap indexMap; - const QLatin1String oldKey("CluceneSearchNamespaces"); - if (!engine.customValue(oldKey, QString()).isNull()) { - // old style qhc file < 4.4.2, need to convert... - const QStringList indexedNamespaces = engine.customValue(oldKey). - toString().split(QLatin1String("|"), QString::SkipEmptyParts); - foreach (const QString &nameSpace, indexedNamespaces) - indexMap.insert(nameSpace, QDateTime()); - engine.removeCustomValue(oldKey); - } else { - QDataStream dataStream(engine.customValue(key).toByteArray()); - dataStream >> indexMap; - } + const QLatin1String key("CluceneIndexedNamespaces"); + if (reindex) + engine.setCustomValue(key, QLatin1String("")); + + QMap indexMap; + const QLatin1String oldKey("CluceneSearchNamespaces"); + if (!engine.customValue(oldKey, QString()).isNull()) { + // old style qhc file < 4.4.2, need to convert... + const QStringList indexedNamespaces + = engine.customValue(oldKey).toString() + .split(QLatin1String("|"), QString::SkipEmptyParts); + foreach (const QString &nameSpace, indexedNamespaces) + indexMap.insert(nameSpace, QDateTime()); + engine.removeCustomValue(oldKey); + } else { + QDataStream dataStream(engine.customValue(key).toByteArray()); + dataStream >> indexMap; + } - QString indexPath = m_indexFilesFolder; + QString indexPath = m_indexFilesFolder; - QFileInfo fInfo(indexPath); - if (fInfo.exists() && !fInfo.isWritable()) { - qWarning("Full Text Search, could not create index (missing permissions for '%s').", qPrintable(indexPath)); - return; - } + QFileInfo fInfo(indexPath); + if (fInfo.exists() && !fInfo.isWritable()) { + qWarning("Full Text Search, could not create index (missing permissions for '%s').", + qPrintable(indexPath)); + return; + } - emit indexingStarted(); + emit indexingStarted(); - QCLuceneIndexWriter *writer = 0; - QCLuceneStandardAnalyzer analyzer; - const QStringList registeredDocs = engine.registeredDocumentations(); + QCLuceneIndexWriter *writer = 0; + QCLuceneStandardAnalyzer analyzer; + const QStringList registeredDocs = engine.registeredDocumentations(); - QLocalSocket localSocket; - localSocket.connectToServer(QString(QLatin1String("QtAssistant%1")) - .arg(QLatin1String(QT_VERSION_STR))); + QLocalSocket localSocket; + localSocket.connectToServer(QString(QLatin1String("QtAssistant%1")) + .arg(QLatin1String(QT_VERSION_STR))); - QLocalServer localServer; - bool otherInstancesRunning = true; - if (!localSocket.waitForConnected()) { - otherInstancesRunning = false; - localServer.listen(QString(QLatin1String("QtAssistant%1")) - .arg(QLatin1String(QT_VERSION_STR))); - } + QLocalServer localServer; + bool otherInstancesRunning = true; + if (!localSocket.waitForConnected()) { + otherInstancesRunning = false; + localServer.listen(QString(QLatin1String("QtAssistant%1")) + .arg(QLatin1String(QT_VERSION_STR))); + } -#if !defined(QT_NO_EXCEPTIONS) - try { -#endif // check if it's locked, and if the other instance is running if (!otherInstancesRunning && QCLuceneIndexReader::isLocked(indexPath)) QCLuceneIndexReader::unlock(indexPath); @@ -705,7 +707,8 @@ void QHelpSearchIndexWriter::run() removeDocuments(indexPath, namespaceName); } else { QString path = engine.documentationFileName(namespaceName); - if (indexMap.value(namespaceName) < QFileInfo(path).lastModified()) { + if (indexMap.value(namespaceName) + < QFileInfo(path).lastModified()) { // make sure we remove some outdated indexed stuff indexMap.remove(namespaceName); removeDocuments(indexPath, namespaceName); @@ -728,94 +731,85 @@ void QHelpSearchIndexWriter::run() indexMap.clear(); writer = new QCLuceneIndexWriter(indexPath, analyzer, true); } -#if !defined(QT_NO_EXCEPTIONS) - } catch (...) { - qWarning("Full Text Search, could not create index writer in '%s'.", - qPrintable(indexPath)); - return; - } -#endif -#if !defined(QT_NO_EXCEPTIONS) - try { -#endif writer->setMergeFactor(100); writer->setMinMergeDocs(1000); writer->setMaxFieldLength(QCLuceneIndexWriter::DEFAULT_MAX_FIELD_LENGTH); -#if !defined(QT_NO_EXCEPTIONS) - } catch (...) { - qWarning("Full Text Search, could not set writer properties."); - return; - } -#endif - QStringList namespaces; - foreach(const QString &namespaceName, registeredDocs) { - mutexLocker.relock(); - if (m_cancel) { - closeIndexWriter(writer); - emit indexingFinished(); - return; - } - mutexLocker.unlock(); + QStringList namespaces; + foreach(const QString &namespaceName, registeredDocs) { + mutexLocker.relock(); + if (m_cancel) { + closeIndexWriter(writer); + emit indexingFinished(); + return; + } + mutexLocker.unlock(); - namespaces.append(namespaceName); - if (indexMap.contains(namespaceName)) - continue; + namespaces.append(namespaceName); + if (indexMap.contains(namespaceName)) + continue; - const QList attributeSets = - engine.filterAttributeSets(namespaceName); + const QList attributeSets = + engine.filterAttributeSets(namespaceName); - if (attributeSets.isEmpty()) { - const QList docFiles = indexableFiles(&engine, namespaceName, - QStringList()); - if (!addDocuments(docFiles, engine, QStringList(), namespaceName, - writer, analyzer)) - break; - } else { - bool bail = false; - foreach (const QStringList &attributes, attributeSets) { - const QList docFiles = indexableFiles(&engine, - namespaceName, attributes); - if (!addDocuments(docFiles, engine, attributes, namespaceName, - writer, analyzer)) { - bail = true; + if (attributeSets.isEmpty()) { + const QList docFiles = indexableFiles(&engine, namespaceName, + QStringList()); + if (!addDocuments(docFiles, engine, QStringList(), namespaceName, + writer, analyzer)) break; + } else { + bool bail = false; + foreach (const QStringList &attributes, attributeSets) { + const QList docFiles = indexableFiles(&engine, + namespaceName, attributes); + if (!addDocuments(docFiles, engine, attributes, namespaceName, + writer, analyzer)) { + bail = true; + break; + } } + if (bail) + break; } - if (bail) - break; - } - mutexLocker.relock(); - if (!m_cancel) { - QString path(engine.documentationFileName(namespaceName)); - indexMap.insert(namespaceName, QFileInfo(path).lastModified()); - writeIndexMap(engine, indexMap); + mutexLocker.relock(); + if (!m_cancel) { + QString path(engine.documentationFileName(namespaceName)); + indexMap.insert(namespaceName, QFileInfo(path).lastModified()); + writeIndexMap(engine, indexMap); + } + mutexLocker.unlock(); } - mutexLocker.unlock(); - } - closeIndexWriter(writer); + closeIndexWriter(writer); - mutexLocker.relock(); - if (!m_cancel) { - mutexLocker.unlock(); - - QStringList indexedNamespaces = indexMap.keys(); - foreach(const QString &namespaceName, indexedNamespaces) { - mutexLocker.relock(); - if (m_cancel) - break; + mutexLocker.relock(); + if (!m_cancel) { mutexLocker.unlock(); - if (!namespaces.contains(namespaceName)) { - indexMap.remove(namespaceName); - writeIndexMap(engine, indexMap); - removeDocuments(indexPath, namespaceName); + QStringList indexedNamespaces = indexMap.keys(); + foreach(const QString &namespaceName, indexedNamespaces) { + mutexLocker.relock(); + if (m_cancel) + break; + mutexLocker.unlock(); + + if (!namespaces.contains(namespaceName)) { + indexMap.remove(namespaceName); + writeIndexMap(engine, indexMap); + removeDocuments(indexPath, namespaceName); + } } } + +#if !defined(QT_NO_EXCEPTIONS) + } catch (...) { + qWarning("%s: Failed because of CLucene exception.", Q_FUNC_INFO); } +#endif + emit indexingFinished(); } -- cgit v0.12 From 4971430290ecb11012ef5cbf8ef041da0ec3a824 Mon Sep 17 00:00:00 2001 From: Zeno Albisser Date: Thu, 18 Feb 2010 11:16:26 +0100 Subject: Revert "Added note to make QList destructor virtual in version 5" Virtual functions should not be used with copyable types due to slicing. This reverts commit c1db6c2c5a3bbe96a628207af169a032d535426f. --- src/corelib/tools/qlist.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index a549f2f..1ad7528 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -112,7 +112,7 @@ class QList public: inline QList() : d(&QListData::shared_null) { d->ref.ref(); } inline QList(const QList &l) : d(l.d) { d->ref.ref(); if (!d->sharable) detach_helper(); } - ~QList(); // ### Qt5: make this destructor virtual + ~QList(); QList &operator=(const QList &l); bool operator==(const QList &l) const; inline bool operator!=(const QList &l) const { return !(*this == l); } -- cgit v0.12 From 2e8af9b06f7c25710253e517325644b5fa1ba17f Mon Sep 17 00:00:00 2001 From: ck Date: Thu, 18 Feb 2010 11:21:11 +0100 Subject: Help system: Remove hard-coded qt namespace. Task-number: QTBUG-7821 Reviewed-by: kh1 --- tools/assistant/lib/qhelpsearchengine.cpp | 6 +++--- tools/assistant/lib/qhelpsearchindexreader.cpp | 6 ++---- tools/assistant/lib/qhelpsearchindexreader_clucene.cpp | 10 ++++------ tools/assistant/lib/qhelpsearchindexreader_clucene_p.h | 10 ++++------ tools/assistant/lib/qhelpsearchindexreader_default.cpp | 10 ++++------ tools/assistant/lib/qhelpsearchindexreader_default_p.h | 10 ++++------ tools/assistant/lib/qhelpsearchindexreader_p.h | 6 ++---- tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp | 10 ++++------ tools/assistant/lib/qhelpsearchindexwriter_clucene_p.h | 9 ++++----- tools/assistant/lib/qhelpsearchindexwriter_default.cpp | 10 ++++------ tools/assistant/lib/qhelpsearchindexwriter_default_p.h | 10 ++++------ 11 files changed, 39 insertions(+), 58 deletions(-) diff --git a/tools/assistant/lib/qhelpsearchengine.cpp b/tools/assistant/lib/qhelpsearchengine.cpp index 7c2635d..9914efa 100644 --- a/tools/assistant/lib/qhelpsearchengine.cpp +++ b/tools/assistant/lib/qhelpsearchengine.cpp @@ -63,9 +63,9 @@ QT_BEGIN_NAMESPACE #if defined(QT_CLUCENE_SUPPORT) - using namespace qt::fulltextsearch::clucene; + using namespace fulltextsearch::clucene; #else - using namespace qt::fulltextsearch::std; + using namespace fulltextsearch::std; #endif class QHelpSearchEnginePrivate : public QObject @@ -195,7 +195,7 @@ private: QHelpSearchQueryWidget *queryWidget; QHelpSearchResultWidget *resultWidget; - qt::fulltextsearch::QHelpSearchIndexReader *indexReader; + fulltextsearch::QHelpSearchIndexReader *indexReader; QHelpSearchIndexWriter *indexWriter; QPointer helpEngine; diff --git a/tools/assistant/lib/qhelpsearchindexreader.cpp b/tools/assistant/lib/qhelpsearchindexreader.cpp index 92d7658..e79fca6 100644 --- a/tools/assistant/lib/qhelpsearchindexreader.cpp +++ b/tools/assistant/lib/qhelpsearchindexreader.cpp @@ -43,8 +43,7 @@ QT_BEGIN_NAMESPACE -namespace qt { - namespace fulltextsearch { +namespace fulltextsearch { QHelpSearchIndexReader::QHelpSearchIndexReader() : QThread() @@ -100,7 +99,6 @@ QList QHelpSearchIndexReader::hits(int start, } - } // namespace fulltextsearch -} // namespace qt +} // namespace fulltextsearch QT_END_NAMESPACE diff --git a/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp b/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp index b5bec44..b050361 100644 --- a/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp +++ b/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp @@ -55,9 +55,8 @@ QT_BEGIN_NAMESPACE -namespace qt { - namespace fulltextsearch { - namespace clucene { +namespace fulltextsearch { +namespace clucene { QHelpSearchIndexReaderClucene::QHelpSearchIndexReaderClucene() : QHelpSearchIndexReader() @@ -387,8 +386,7 @@ void QHelpSearchIndexReaderClucene::boostSearchHits(const QHelpEngineCore &engin } } - } // namespace clucene - } // namespace fulltextsearch -} // namespace qt +} // namespace clucene +} // namespace fulltextsearch QT_END_NAMESPACE diff --git a/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h b/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h index 3e3b9dd..8f51cb1 100644 --- a/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h +++ b/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h @@ -60,9 +60,8 @@ QT_BEGIN_NAMESPACE -namespace qt { - namespace fulltextsearch { - namespace clucene { +namespace fulltextsearch { +namespace clucene { class QHelpSearchIndexReaderClucene : public QHelpSearchIndexReader { @@ -84,9 +83,8 @@ private: const QList &queryList); }; - } // namespace clucene - } // namespace fulltextsearch -} // namespace qt +} // namespace clucene +} // namespace fulltextsearch QT_END_NAMESPACE diff --git a/tools/assistant/lib/qhelpsearchindexreader_default.cpp b/tools/assistant/lib/qhelpsearchindexreader_default.cpp index d2241a5..11a50d9 100644 --- a/tools/assistant/lib/qhelpsearchindexreader_default.cpp +++ b/tools/assistant/lib/qhelpsearchindexreader_default.cpp @@ -52,9 +52,8 @@ QT_BEGIN_NAMESPACE -namespace qt { - namespace fulltextsearch { - namespace std { +namespace fulltextsearch { +namespace std { namespace { QStringList split( const QString &str ) @@ -607,8 +606,7 @@ void QHelpSearchIndexReaderDefault::run() emit searchingFinished(hitList.count()); } - } // namespace std - } // namespace fulltextsearch -} // namespace qt +} // namespace std +} // namespace fulltextsearch QT_END_NAMESPACE diff --git a/tools/assistant/lib/qhelpsearchindexreader_default_p.h b/tools/assistant/lib/qhelpsearchindexreader_default_p.h index 8c80608..b30fa4b 100644 --- a/tools/assistant/lib/qhelpsearchindexreader_default_p.h +++ b/tools/assistant/lib/qhelpsearchindexreader_default_p.h @@ -64,9 +64,8 @@ QT_BEGIN_NAMESPACE struct Entry; struct PosEntry; -namespace qt { - namespace fulltextsearch { - namespace std { +namespace fulltextsearch { +namespace std { class Reader { @@ -127,9 +126,8 @@ private: Reader m_reader; }; - } // namespace std - } // namespace fulltextsearch -} // namespace qt +} // namespace std +} // namespace fulltextsearch QT_END_NAMESPACE diff --git a/tools/assistant/lib/qhelpsearchindexreader_p.h b/tools/assistant/lib/qhelpsearchindexreader_p.h index b309f46..4d27c0f 100644 --- a/tools/assistant/lib/qhelpsearchindexreader_p.h +++ b/tools/assistant/lib/qhelpsearchindexreader_p.h @@ -66,8 +66,7 @@ QT_BEGIN_NAMESPACE class QHelpEngineCore; -namespace qt { - namespace fulltextsearch { +namespace fulltextsearch { class QHelpSearchIndexReader : public QThread { @@ -100,8 +99,7 @@ private: virtual void run()=0; }; - } // namespace fulltextsearch -} // namespace qt +} // namespace fulltextsearch QT_END_NAMESPACE diff --git a/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp b/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp index 2eeefb5..59067cf 100644 --- a/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp +++ b/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp @@ -63,9 +63,8 @@ QT_BEGIN_NAMESPACE -namespace qt { - namespace fulltextsearch { - namespace clucene { +namespace fulltextsearch { +namespace clucene { // taken from qtexthtmlparser static const struct QTextHtmlEntity @@ -895,8 +894,7 @@ void QHelpSearchIndexWriter::closeIndexWriter(QCLuceneIndexWriter *writer) #endif } - } // namespace clucene - } // namespace fulltextsearch -} // namespace qt +} // namespace clucene +} // namespace fulltextsearch QT_END_NAMESPACE diff --git a/tools/assistant/lib/qhelpsearchindexwriter_clucene_p.h b/tools/assistant/lib/qhelpsearchindexwriter_clucene_p.h index 91b8abd..db1e533 100644 --- a/tools/assistant/lib/qhelpsearchindexwriter_clucene_p.h +++ b/tools/assistant/lib/qhelpsearchindexwriter_clucene_p.h @@ -69,9 +69,8 @@ QT_BEGIN_NAMESPACE class QCLuceneIndexWriter; -namespace qt { - namespace fulltextsearch { - namespace clucene { +namespace fulltextsearch { +namespace clucene { class QHelpSearchIndexWriter : public QThread { @@ -116,9 +115,9 @@ private: QString m_indexFilesFolder; }; - } // namespace clucene - } // namespace fulltextsearch } // namespace clucene +} // namespace fulltextsearch + QT_END_NAMESPACE diff --git a/tools/assistant/lib/qhelpsearchindexwriter_default.cpp b/tools/assistant/lib/qhelpsearchindexwriter_default.cpp index 6d09fb8..cb3e49c 100644 --- a/tools/assistant/lib/qhelpsearchindexwriter_default.cpp +++ b/tools/assistant/lib/qhelpsearchindexwriter_default.cpp @@ -55,9 +55,8 @@ QT_BEGIN_NAMESPACE -namespace qt { - namespace fulltextsearch { - namespace std { +namespace fulltextsearch { +namespace std { Writer::Writer(const QString &path) : indexPath(path) @@ -379,8 +378,7 @@ QString QHelpSearchIndexWriter::removeNamespace(const QString namespaces, return value; } - } // namespace std - } // namespace fulltextsearch -} // namespace qt +} // namespace std +} // namespace fulltextsearch QT_END_NAMESPACE diff --git a/tools/assistant/lib/qhelpsearchindexwriter_default_p.h b/tools/assistant/lib/qhelpsearchindexwriter_default_p.h index b222203..625cb84 100644 --- a/tools/assistant/lib/qhelpsearchindexwriter_default_p.h +++ b/tools/assistant/lib/qhelpsearchindexwriter_default_p.h @@ -65,9 +65,8 @@ QT_BEGIN_NAMESPACE -namespace qt { - namespace fulltextsearch { - namespace std { +namespace fulltextsearch { +namespace std { class Writer { @@ -123,9 +122,8 @@ private: QString m_indexFilesFolder; }; - } // namespace std - } // namespace fulltextsearch -} // namespace qt +} // namespace std +} // namespace fulltextsearch QT_END_NAMESPACE -- cgit v0.12 From a4332ce058cf3fe567b386d300ba740442a69f44 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Wed, 17 Feb 2010 16:36:40 +0100 Subject: QNAM HTTP: Always set channel.reply to 0 when done This will help us to track down a sporadic bug that made requests being sent again even if they were already done. Reviewed-by: Peter Hartmann --- src/network/access/qhttpnetworkconnection.cpp | 12 +----------- src/network/access/qhttpnetworkconnection_p.h | 5 ----- src/network/access/qhttpnetworkconnectionchannel.cpp | 17 ++++++++++++++--- src/network/access/qhttpnetworkreply.cpp | 13 ++++++++++--- src/network/access/qhttpnetworkreply_p.h | 2 ++ 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index cc6a1c8..327d2db 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -404,6 +404,7 @@ QHttpNetworkReply* QHttpNetworkConnectionPrivate::queueRequest(const QHttpNetwor QHttpNetworkReply *reply = new QHttpNetworkReply(request.url()); reply->setRequest(request); reply->d_func()->connection = q; + reply->d_func()->connectionChannel = &channels[0]; // will have the correct one set later HttpMessagePair pair = qMakePair(request, reply); switch (request.priority()) { @@ -861,17 +862,6 @@ QNetworkProxy QHttpNetworkConnection::transparentProxy() const // SSL support below #ifndef QT_NO_OPENSSL -QSslConfiguration QHttpNetworkConnectionPrivate::sslConfiguration(const QHttpNetworkReply &reply) const -{ - if (!encrypt) - return QSslConfiguration(); - - for (int i = 0; i < channelCount; ++i) - if (channels[i].reply == &reply) - return static_cast(channels[0].socket)->sslConfiguration(); - return QSslConfiguration(); // pending or done request -} - void QHttpNetworkConnection::setSslConfiguration(const QSslConfiguration &config) { Q_D(QHttpNetworkConnection); diff --git a/src/network/access/qhttpnetworkconnection_p.h b/src/network/access/qhttpnetworkconnection_p.h index 03cf09c..823774e 100644 --- a/src/network/access/qhttpnetworkconnection_p.h +++ b/src/network/access/qhttpnetworkconnection_p.h @@ -210,11 +210,6 @@ public: void emitReplyError(QAbstractSocket *socket, QHttpNetworkReply *reply, QNetworkReply::NetworkError errorCode); bool handleAuthenticateChallenge(QAbstractSocket *socket, QHttpNetworkReply *reply, bool isProxy, bool &resend); - -#ifndef QT_NO_OPENSSL - QSslConfiguration sslConfiguration(const QHttpNetworkReply &reply) const; -#endif - #ifndef QT_NO_NETWORKPROXY QNetworkProxy networkProxy; void emitProxyAuthenticationRequired(const QHttpNetworkConnectionChannel *chan, const QNetworkProxy &proxy, QAuthenticator* auth); diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index 2a3036b..89fd032 100644 --- a/src/network/access/qhttpnetworkconnectionchannel.cpp +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -137,6 +137,7 @@ bool QHttpNetworkConnectionChannel::sendRequest() if (reply) { reply->d_func()->clear(); reply->d_func()->connection = connection; + reply->d_func()->connectionChannel = this; reply->d_func()->autoDecompress = request.d->autoDecompress; reply->d_func()->pipeliningUsed = false; } @@ -568,7 +569,8 @@ void QHttpNetworkConnectionChannel::allDone() handleStatus(); // ### at this point there should be no more data on the socket // close if server requested - if (reply->d_func()->isConnectionCloseEnabled()) + bool connectionCloseEnabled = reply->d_func()->isConnectionCloseEnabled(); + if (connectionCloseEnabled) close(); // queue the finished signal, this is required since we might send new requests from // slot connected to it. The socket will not fire readyRead signal, if we are already @@ -579,14 +581,22 @@ void QHttpNetworkConnectionChannel::allDone() // in case of failures, each channel will attempt two reconnects before emitting error. reconnectAttempts = 2; + detectPipeliningSupport(); + // now the channel can be seen as free/idle again, all signal emissions for the reply have been done this->state = QHttpNetworkConnectionChannel::IdleState; - detectPipeliningSupport(); + // if it does not need to be sent again we can set it to 0 + // the previous code did not do that and we had problems with accidental re-sending of a + // finished request. + // Note that this may trigger a segfault at some other point. But then we can fix the underlying + // problem. + if (!resendCurrent) + reply = 0; // move next from pipeline to current request if (!alreadyPipelinedRequests.isEmpty()) { - if (resendCurrent || reply->d_func()->isConnectionCloseEnabled() || socket->state() != QAbstractSocket::ConnectedState) { + if (resendCurrent || connectionCloseEnabled || socket->state() != QAbstractSocket::ConnectedState) { // move the pipelined ones back to the main queue requeueCurrentlyPipelinedRequests(); close(); @@ -745,6 +755,7 @@ void QHttpNetworkConnectionChannel::pipelineInto(HttpMessagePair &pair) if (reply) { reply->d_func()->clear(); reply->d_func()->connection = connection; + reply->d_func()->connectionChannel = this; reply->d_func()->autoDecompress = request.d->autoDecompress; reply->d_func()->pipeliningUsed = true; } diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp index 512c045..984f557 100644 --- a/src/network/access/qhttpnetworkreply.cpp +++ b/src/network/access/qhttpnetworkreply.cpp @@ -230,6 +230,7 @@ void QHttpNetworkReplyPrivate::clear() currentChunkRead = 0; connectionCloseEnabled = true; connection = 0; + connectionChannel = 0; #ifndef QT_NO_COMPRESS if (initInflate) inflateEnd(&inflateStrm); @@ -803,9 +804,15 @@ void QHttpNetworkReplyPrivate::eraseData() QSslConfiguration QHttpNetworkReply::sslConfiguration() const { Q_D(const QHttpNetworkReply); - if (d->connection) - return d->connection->d_func()->sslConfiguration(*this); - return QSslConfiguration(); + + if (!d->connectionChannel) + return QSslConfiguration(); + + QSslSocket *sslSocket = qobject_cast(d->connectionChannel->socket); + if (!sslSocket) + return QSslConfiguration(); + + return sslSocket->sslConfiguration(); } void QHttpNetworkReply::setSslConfiguration(const QSslConfiguration &config) diff --git a/src/network/access/qhttpnetworkreply_p.h b/src/network/access/qhttpnetworkreply_p.h index af9266b..fa240ec 100644 --- a/src/network/access/qhttpnetworkreply_p.h +++ b/src/network/access/qhttpnetworkreply_p.h @@ -86,6 +86,7 @@ static const unsigned char gz_magic[2] = {0x1f, 0x8b}; // gzip magic header QT_BEGIN_NAMESPACE class QHttpNetworkConnection; +class QHttpNetworkConnectionChannel; class QHttpNetworkRequest; class QHttpNetworkConnectionPrivate; class QHttpNetworkReplyPrivate; @@ -218,6 +219,7 @@ public: qint64 currentChunkSize; qint64 currentChunkRead; QPointer connection; + QPointer connectionChannel; bool initInflate; bool streamEnd; #ifndef QT_NO_COMPRESS -- cgit v0.12 From 90c3e1d2110c47ad36e05c04c874d6d932dd772f Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Thu, 18 Feb 2010 14:41:20 +0100 Subject: QNAM HTTP: Clean code a bit .. and some changes that will help us track down bugs Reviewed-by: Peter Hartmann --- src/network/access/qhttpnetworkconnection.cpp | 10 ++-- .../access/qhttpnetworkconnectionchannel.cpp | 64 ++++++++++++++-------- 2 files changed, 45 insertions(+), 29 deletions(-) diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index 327d2db..62aa2d7 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -689,14 +689,12 @@ void QHttpNetworkConnectionPrivate::_q_startNextRequest() if (channels[i].resendCurrent) { channels[i].resendCurrent = false; channels[i].state = QHttpNetworkConnectionChannel::IdleState; - if (channels[i].reply) { - // if this is not possible, error will be emitted and connection terminated - if (!channels[i].resetUploadData()) - continue; + // if this is not possible, error will be emitted and connection terminated + if (!channels[i].resetUploadData()) + continue; - channels[i].sendRequest(); - } + channels[i].sendRequest(); } } diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index 89fd032..dbee72a 100644 --- a/src/network/access/qhttpnetworkconnectionchannel.cpp +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -124,6 +124,13 @@ void QHttpNetworkConnectionChannel::close() bool QHttpNetworkConnectionChannel::sendRequest() { + if (!reply) { + // heh, how should that happen! + qWarning() << "QHttpNetworkConnectionChannel::sendRequest() called without QHttpNetworkReply"; + state = QHttpNetworkConnectionChannel::IdleState; + return false; + } + switch (state) { case QHttpNetworkConnectionChannel::IdleState: { // write the header if (!ensureConnection()) { @@ -134,14 +141,13 @@ bool QHttpNetworkConnectionChannel::sendRequest() } written = 0; // excluding the header bytesTotal = 0; - if (reply) { - reply->d_func()->clear(); - reply->d_func()->connection = connection; - reply->d_func()->connectionChannel = this; - reply->d_func()->autoDecompress = request.d->autoDecompress; - reply->d_func()->pipeliningUsed = false; - } - state = QHttpNetworkConnectionChannel::WritingState; + + reply->d_func()->clear(); + reply->d_func()->connection = connection; + reply->d_func()->connectionChannel = this; + reply->d_func()->autoDecompress = request.d->autoDecompress; + reply->d_func()->pipeliningUsed = false; + pendingEncrypt = false; // if the url contains authentication parameters, use the new ones // both channels will use the new authentication parameters @@ -175,13 +181,15 @@ bool QHttpNetworkConnectionChannel::sendRequest() QObject::connect(uploadByteDevice, SIGNAL(readyRead()),this, SLOT(_q_uploadDataReadyRead())); bytesTotal = request.contentLength(); + + state = QHttpNetworkConnectionChannel::WritingState; // start writing data + sendRequest(); //recurse } else { - state = QHttpNetworkConnectionChannel::WaitingState; - sendRequest(); - break; + state = QHttpNetworkConnectionChannel::WaitingState; // now wait for response + sendRequest(); //recurse } - // write the initial chunk together with the headers - // fall through + + break; } case QHttpNetworkConnectionChannel::WritingState: { @@ -191,7 +199,7 @@ bool QHttpNetworkConnectionChannel::sendRequest() if (uploadByteDevice) emit reply->dataSendProgress(written, bytesTotal); state = QHttpNetworkConnectionChannel::WaitingState; // now wait for response - sendRequest(); + sendRequest(); // recurse break; } @@ -279,16 +287,25 @@ void QHttpNetworkConnectionChannel::_q_receiveReply() { Q_ASSERT(socket); + if (!reply) { + // heh, how should that happen! + qWarning() << "QHttpNetworkConnectionChannel::_q_receiveReply() called without QHttpNetworkReply," + << socket->bytesAvailable() << "bytes on socket."; + close(); + return; + } + qint64 bytes = 0; QAbstractSocket::SocketState socketState = socket->state(); // connection might be closed to signal the end of data if (socketState == QAbstractSocket::UnconnectedState) { if (socket->bytesAvailable() <= 0) { - if (reply && reply->d_func()->state == QHttpNetworkReplyPrivate::ReadingDataState) { + if (reply->d_func()->state == QHttpNetworkReplyPrivate::ReadingDataState) { // finish this reply. this case happens when the server did not send a content length reply->d_func()->state = QHttpNetworkReplyPrivate::AllDoneState; allDone(); + return; } else { handleUnexpectedEOF(); return; @@ -300,12 +317,13 @@ void QHttpNetworkConnectionChannel::_q_receiveReply() // read loop for the response while (socket->bytesAvailable()) { - QHttpNetworkReplyPrivate::ReplyState state = reply ? reply->d_func()->state : QHttpNetworkReplyPrivate::AllDoneState; + QHttpNetworkReplyPrivate::ReplyState state = reply->d_func()->state; switch (state) { case QHttpNetworkReplyPrivate::NothingDoneState: { // only eat whitespace on the first call eatWhitespace(); state = reply->d_func()->state = QHttpNetworkReplyPrivate::ReadingStatusState; + // fallthrough } case QHttpNetworkReplyPrivate::ReadingStatusState: { qint64 statusBytes = reply->d_func()->readStatus(socket); @@ -413,8 +431,10 @@ void QHttpNetworkConnectionChannel::_q_receiveReply() #endif } } + // still in ReadingDataState? This function will be called again by the socket's readyRead if (replyPrivate->state == QHttpNetworkReplyPrivate::ReadingDataState) break; + // everything done, fall through } case QHttpNetworkReplyPrivate::AllDoneState: @@ -752,13 +772,11 @@ void QHttpNetworkConnectionChannel::pipelineInto(HttpMessagePair &pair) QHttpNetworkRequest &request = pair.first; QHttpNetworkReply *reply = pair.second; - if (reply) { - reply->d_func()->clear(); - reply->d_func()->connection = connection; - reply->d_func()->connectionChannel = this; - reply->d_func()->autoDecompress = request.d->autoDecompress; - reply->d_func()->pipeliningUsed = true; - } + reply->d_func()->clear(); + reply->d_func()->connection = connection; + reply->d_func()->connectionChannel = this; + reply->d_func()->autoDecompress = request.d->autoDecompress; + reply->d_func()->pipeliningUsed = true; #ifndef QT_NO_NETWORKPROXY QByteArray header = QHttpNetworkRequestPrivate::header(request, -- cgit v0.12 From 9d8614d8dcd1ae8389842aa4c48d8c77ae69bf27 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Thu, 18 Feb 2010 15:11:10 +0100 Subject: tst_qnetworkreply: Add another testcase Reviewed-by: Peter Hartmann --- tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 66 ++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index 5fecc86..049bbb8 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -257,6 +257,8 @@ private Q_SLOTS: void httpConnectionCount(); + void httpRecursiveCreation(); + #ifndef QT_NO_OPENSSL void ioPostToHttpsUploadProgress(); void ignoreSslErrorsList_data(); @@ -3788,6 +3790,70 @@ void tst_QNetworkReply::httpConnectionCount() #endif } +class HttpRecursiveCreationHelper : public QObject { + Q_OBJECT +public: + + HttpRecursiveCreationHelper(): + QObject(0), + requestsStartedCount_finished(0), + requestsStartedCount_readyRead(0), + requestsFinishedCount(0) + { + } + QNetworkAccessManager manager; + int requestsStartedCount_finished; + int requestsStartedCount_readyRead; + int requestsFinishedCount; +public slots: + void finishedSlot() { + requestsFinishedCount++; + + QNetworkReply *reply = qobject_cast(sender()); + QVERIFY(!reply->error()); + QVERIFY(reply->bytesAvailable() == 27906); + + if (requestsFinishedCount == 60) { + QTestEventLoop::instance().exitLoop(); + return; + } + + if (requestsStartedCount_finished < 30) { + startOne(); + requestsStartedCount_finished++; + } + + reply->deleteLater(); + } + void readyReadSlot() { + QNetworkReply *reply = qobject_cast(sender()); + QVERIFY(!reply->error()); + + if (requestsStartedCount_readyRead < 30 && reply->bytesAvailable() > 27906/2) { + startOne(); + requestsStartedCount_readyRead++; + } + } + void startOne() { + QUrl url = "http://" + QtNetworkSettings::serverName() + "/gif/fluke.gif"; + QNetworkRequest request(url); + QNetworkReply *reply = manager.get(request); + reply->setParent(this); + connect(reply, SIGNAL(finished()), this, SLOT(finishedSlot())); + connect(reply, SIGNAL(readyRead()), this, SLOT(readyReadSlot())); + } +}; + +void tst_QNetworkReply::httpRecursiveCreation() +{ + // this test checks if creation of new requests to the same host properly works + // from readyRead() and finished() signals + HttpRecursiveCreationHelper helper; + helper.startOne(); + QTestEventLoop::instance().enterLoop(30); + QVERIFY(!QTestEventLoop::instance().timeout()); +} + #ifndef QT_NO_OPENSSL void tst_QNetworkReply::ignoreSslErrorsList_data() { -- cgit v0.12 From 4c08defe1ac8342b9f8c6aeceebec12b839bae2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Thu, 18 Feb 2010 14:36:46 +0100 Subject: Simplify code, fix a compiler warning... profit! Well, it was a compiler warning on master... :-/ Reviewed-by: Janne Anttila Reviewed-by: axis --- src/gui/kernel/qsoftkeymanager.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/gui/kernel/qsoftkeymanager.cpp b/src/gui/kernel/qsoftkeymanager.cpp index d3cef86..c9a94ee 100644 --- a/src/gui/kernel/qsoftkeymanager.cpp +++ b/src/gui/kernel/qsoftkeymanager.cpp @@ -210,13 +210,11 @@ bool QSoftKeyManager::handleUpdateSoftKeys() d->requestedSoftKeyActions.clear(); bool recursiveMerging = false; QWidget *source = softkeySource(NULL, recursiveMerging); - do { - if (source) { - bool added = appendSoftkeys(*source, level); - source = softkeySource(source, recursiveMerging); - level = added ? level + 1 : level; - } - } while (source); + while (source) { + if (appendSoftkeys(*source, level)) + ++level; + source = softkeySource(source, recursiveMerging); + } d->updateSoftKeys_sys(); return true; -- cgit v0.12 From 7f01b5aa56e61048a9785040e9807fd871a4b59a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Thu, 18 Feb 2010 16:36:44 +0100 Subject: QTreeView: Fix premature pessimization Reviewed-by: Olivier Goffart --- src/gui/itemviews/qtreeview.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp index d0fa22d..706d2a8 100644 --- a/src/gui/itemviews/qtreeview.cpp +++ b/src/gui/itemviews/qtreeview.cpp @@ -2474,10 +2474,11 @@ void QTreeView::rowsInserted(const QModelIndex &parent, int start, int end) QVector insertedItems(delta); for (int i = 0; i < delta; ++i) { - insertedItems[i].index = d->model->index(i + start, 0, parent); - insertedItems[i].level = childLevel; - insertedItems[i].hasChildren = d->hasVisibleChildren(insertedItems[i].index); - insertedItems[i].hasMoreSiblings = !((i == delta - 1) && (parentRowCount == end +1)); + QTreeViewItem &item = insertedItems[i]; + item.index = d->model->index(i + start, 0, parent); + item.level = childLevel; + item.hasChildren = d->hasVisibleChildren(item.index); + item.hasMoreSiblings = !((i == delta - 1) && (parentRowCount == end +1)); } if (d->viewItems.isEmpty()) d->defaultItemHeight = indexRowSizeHint(insertedItems[0].index); -- cgit v0.12 From b408d94902ef0b2856a4c462e06fcc4412de49be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Fri, 12 Feb 2010 18:31:54 +0100 Subject: Fixing QDir benchmarks... The initial state of QDirIterator is ill-defined. If the hasNext returns true, then one must start by advancing the iterator to the first position. (Rinse, lather, repeat) --- tests/benchmarks/corelib/io/qdir/tst_qdir.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/benchmarks/corelib/io/qdir/tst_qdir.cpp b/tests/benchmarks/corelib/io/qdir/tst_qdir.cpp index aea9fd0..f2e52d2 100644 --- a/tests/benchmarks/corelib/io/qdir/tst_qdir.cpp +++ b/tests/benchmarks/corelib/io/qdir/tst_qdir.cpp @@ -95,9 +95,9 @@ private slots: QBENCHMARK { QDirIterator dit(testdir.path(), QDir::Files); while (dit.hasNext()) { + dit.next(); dit.fileInfo().isDir(); dit.fileInfo().size(); - dit.next(); } } } @@ -116,9 +116,9 @@ private slots: QBENCHMARK { QDirIterator dit(testdir.path()); while (dit.hasNext()) { + dit.next(); dit.fileInfo().isDir(); dit.fileInfo().size(); - dit.next(); } } } -- cgit v0.12 From b8f9453eec3b218317a3dae0acfe444bc00c3093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Fri, 12 Feb 2010 18:36:41 +0100 Subject: Moving QDir benchmarks; making way for new test cases Also, removed dependency on QtGui; gave test case a more meaningful name; using bench_ prefix, instead of tst_ for benchmarks. --- tests/benchmarks/corelib/io/qdir/10000/10000.pro | 10 ++ .../corelib/io/qdir/10000/bench_qdir_10000.cpp | 198 +++++++++++++++++++++ tests/benchmarks/corelib/io/qdir/qdir.pro | 10 +- tests/benchmarks/corelib/io/qdir/tst_qdir.cpp | 198 --------------------- 4 files changed, 210 insertions(+), 206 deletions(-) create mode 100644 tests/benchmarks/corelib/io/qdir/10000/10000.pro create mode 100644 tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp delete mode 100644 tests/benchmarks/corelib/io/qdir/tst_qdir.cpp diff --git a/tests/benchmarks/corelib/io/qdir/10000/10000.pro b/tests/benchmarks/corelib/io/qdir/10000/10000.pro new file mode 100644 index 0000000..93b0992 --- /dev/null +++ b/tests/benchmarks/corelib/io/qdir/10000/10000.pro @@ -0,0 +1,10 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = bench_qdir_10000 +DEPENDPATH += . +INCLUDEPATH += . + +# Input +SOURCES += bench_qdir_10000.cpp + +QT -= gui diff --git a/tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp b/tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp new file mode 100644 index 0000000..b325250 --- /dev/null +++ b/tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp @@ -0,0 +1,198 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#ifdef Q_OS_WIN +# include +#else +# include +# include +# include +# include +#endif + +class bench_QDir_10000 : public QObject{ + Q_OBJECT +public slots: + void initTestCase() { + QDir testdir = QDir::tempPath(); + + const QString subfolder_name = QLatin1String("test_speed"); + QVERIFY(testdir.mkdir(subfolder_name)); + QVERIFY(testdir.cd(subfolder_name)); + + for (uint i=0; i<10000; ++i) { + QFile file(testdir.absolutePath() + "/testfile_" + QString::number(i)); + file.open(QIODevice::WriteOnly); + } + } + void cleanupTestCase() { + { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + testdir.setSorting(QDir::Unsorted); + testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden); + foreach (const QString &filename, testdir.entryList()) { + testdir.remove(filename); + } + } + const QDir temp = QDir(QDir::tempPath()); + temp.rmdir(QLatin1String("test_speed")); + } +private slots: + void baseline() {} + + void sizeSpeed() { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + QBENCHMARK { + QFileInfoList fileInfoList = testdir.entryInfoList(QDir::Files, QDir::Unsorted); + foreach (const QFileInfo &fileInfo, fileInfoList) { + fileInfo.isDir(); + fileInfo.size(); + } + } + } + void sizeSpeedIterator() { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + QBENCHMARK { + QDirIterator dit(testdir.path(), QDir::Files); + while (dit.hasNext()) { + dit.next(); + dit.fileInfo().isDir(); + dit.fileInfo().size(); + } + } + } + + void sizeSpeedWithoutFilter() { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + QBENCHMARK { + QFileInfoList fileInfoList = testdir.entryInfoList(QDir::NoFilter, QDir::Unsorted); + foreach (const QFileInfo &fileInfo, fileInfoList) { + fileInfo.size(); + } + } + } + void sizeSpeedWithoutFilterIterator() { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + QBENCHMARK { + QDirIterator dit(testdir.path()); + while (dit.hasNext()) { + dit.next(); + dit.fileInfo().isDir(); + dit.fileInfo().size(); + } + } + } + + void sizeSpeedWithoutFileInfoList() { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + testdir.setSorting(QDir::Unsorted); + QBENCHMARK { + QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted); + foreach (const QString &filename, fileList) { + QFileInfo fileInfo(filename); + fileInfo.size(); + } + } + } + + void iDontWantAnyStat() { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + testdir.setSorting(QDir::Unsorted); + testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden); + QBENCHMARK { + QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted); + foreach (const QString &filename, fileList) { + + } + } + } + void iDontWantAnyStatIterator() { + QBENCHMARK { + QDirIterator dit(QDir::tempPath() + QLatin1String("/test_speed")); + while (dit.hasNext()) { + dit.next(); + } + } + } + + void sizeSpeedWithoutFilterLowLevel() { +#ifdef Q_OS_WIN + const wchar_t *dirpath = (wchar_t*)testdir.absolutePath().utf16(); + wchar_t appendedPath[MAX_PATH]; + wcscpy(appendedPath, dirpath); + wcscat(appendedPath, L"\\*"); + + WIN32_FIND_DATA fd; + HANDLE hSearch = FindFirstFileW(appendedPath, &fd); + QVERIFY(hSearch == INVALID_HANDLE_VALUE); + + QBENCHMARK { + do { + + } while (FindNextFile(hSearch, &fd)); + } + FindClose(hSearch); +#else + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + DIR *dir = opendir(qPrintable(testdir.absolutePath())); + QVERIFY(dir); + + QVERIFY(!chdir(qPrintable(testdir.absolutePath()))); + QBENCHMARK { + struct dirent *item = readdir(dir); + while (item) { + char *fileName = item->d_name; + + struct stat fileStat; + QVERIFY(!stat(fileName, &fileStat)); + + item = readdir(dir); + } + } + closedir(dir); +#endif + } +}; + +QTEST_MAIN(bench_QDir_10000) +#include "bench_qdir_10000.moc" diff --git a/tests/benchmarks/corelib/io/qdir/qdir.pro b/tests/benchmarks/corelib/io/qdir/qdir.pro index 2cdebfd..c572566 100644 --- a/tests/benchmarks/corelib/io/qdir/qdir.pro +++ b/tests/benchmarks/corelib/io/qdir/qdir.pro @@ -1,8 +1,2 @@ -load(qttest_p4) -TEMPLATE = app -TARGET = tst_qdir -DEPENDPATH += . -INCLUDEPATH += . - -# Input -SOURCES += tst_qdir.cpp +TEMPLATE = subdirs +SUBDIRS = 10000 diff --git a/tests/benchmarks/corelib/io/qdir/tst_qdir.cpp b/tests/benchmarks/corelib/io/qdir/tst_qdir.cpp deleted file mode 100644 index f2e52d2..0000000 --- a/tests/benchmarks/corelib/io/qdir/tst_qdir.cpp +++ /dev/null @@ -1,198 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#ifdef Q_OS_WIN -# include -#else -# include -# include -# include -# include -#endif - -class Test : public QObject{ - Q_OBJECT -public slots: - void initTestCase() { - QDir testdir = QDir::tempPath(); - - const QString subfolder_name = QLatin1String("test_speed"); - QVERIFY(testdir.mkdir(subfolder_name)); - QVERIFY(testdir.cd(subfolder_name)); - - for (uint i=0; i<10000; ++i) { - QFile file(testdir.absolutePath() + "/testfile_" + QString::number(i)); - file.open(QIODevice::WriteOnly); - } - } - void cleanupTestCase() { - { - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); - testdir.setSorting(QDir::Unsorted); - testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden); - foreach (const QString &filename, testdir.entryList()) { - testdir.remove(filename); - } - } - const QDir temp = QDir(QDir::tempPath()); - temp.rmdir(QLatin1String("test_speed")); - } -private slots: - void baseline() {} - - void sizeSpeed() { - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); - QBENCHMARK { - QFileInfoList fileInfoList = testdir.entryInfoList(QDir::Files, QDir::Unsorted); - foreach (const QFileInfo &fileInfo, fileInfoList) { - fileInfo.isDir(); - fileInfo.size(); - } - } - } - void sizeSpeedIterator() { - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); - QBENCHMARK { - QDirIterator dit(testdir.path(), QDir::Files); - while (dit.hasNext()) { - dit.next(); - dit.fileInfo().isDir(); - dit.fileInfo().size(); - } - } - } - - void sizeSpeedWithoutFilter() { - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); - QBENCHMARK { - QFileInfoList fileInfoList = testdir.entryInfoList(QDir::NoFilter, QDir::Unsorted); - foreach (const QFileInfo &fileInfo, fileInfoList) { - fileInfo.size(); - } - } - } - void sizeSpeedWithoutFilterIterator() { - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); - QBENCHMARK { - QDirIterator dit(testdir.path()); - while (dit.hasNext()) { - dit.next(); - dit.fileInfo().isDir(); - dit.fileInfo().size(); - } - } - } - - void sizeSpeedWithoutFileInfoList() { - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); - testdir.setSorting(QDir::Unsorted); - QBENCHMARK { - QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted); - foreach (const QString &filename, fileList) { - QFileInfo fileInfo(filename); - fileInfo.size(); - } - } - } - - void iDontWantAnyStat() { - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); - testdir.setSorting(QDir::Unsorted); - testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden); - QBENCHMARK { - QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted); - foreach (const QString &filename, fileList) { - - } - } - } - void iDontWantAnyStatIterator() { - QBENCHMARK { - QDirIterator dit(QDir::tempPath() + QLatin1String("/test_speed")); - while (dit.hasNext()) { - dit.next(); - } - } - } - - void sizeSpeedWithoutFilterLowLevel() { -#ifdef Q_OS_WIN - const wchar_t *dirpath = (wchar_t*)testdir.absolutePath().utf16(); - wchar_t appendedPath[MAX_PATH]; - wcscpy(appendedPath, dirpath); - wcscat(appendedPath, L"\\*"); - - WIN32_FIND_DATA fd; - HANDLE hSearch = FindFirstFileW(appendedPath, &fd); - QVERIFY(hSearch == INVALID_HANDLE_VALUE); - - QBENCHMARK { - do { - - } while (FindNextFile(hSearch, &fd)); - } - FindClose(hSearch); -#else - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); - DIR *dir = opendir(qPrintable(testdir.absolutePath())); - QVERIFY(dir); - - QVERIFY(!chdir(qPrintable(testdir.absolutePath()))); - QBENCHMARK { - struct dirent *item = readdir(dir); - while (item) { - char *fileName = item->d_name; - - struct stat fileStat; - QVERIFY(!stat(fileName, &fileStat)); - - item = readdir(dir); - } - } - closedir(dir); -#endif - } -}; - -QTEST_MAIN(Test) -#include "tst_qdir.moc" -- cgit v0.12