[Marble-commits] KDE/kdeedu/marble/src/lib
Jens-Michael Hoffmann
jensmh at gmx.de
Sun May 2 02:56:16 CEST 2010
SVN commit 1121645 by jmhoffmann:
DownloadQueueSet: Make jobIsQueued behave O(1) (amortized) instead of O(n).
This speeds up download region considerably when downloading big tile sets.
Testing results for enqueuing phase:
number of tiles time/s before time/s after
================================================
5000 8,8 5,5
20000 68,0 22,8
50000 650,0 86,0
M +33 -9 DownloadQueueSet.cpp
M +13 -1 DownloadQueueSet.h
--- trunk/KDE/kdeedu/marble/src/lib/DownloadQueueSet.cpp #1121644:1121645
@@ -193,17 +193,10 @@
return false;
}
-bool DownloadQueueSet::jobIsQueued( QString const & destinationFileName ) const
+inline bool DownloadQueueSet::jobIsQueued( QString const & destinationFileName ) const
{
- QStack<HttpJob*>::const_iterator pos = m_jobQueue.constBegin();
- QStack<HttpJob*>::const_iterator const end = m_jobQueue.constEnd();
- for (; pos != end; ++pos) {
- if ( (*pos)->destinationFileName() == destinationFileName ) {
- return true;
+ return m_jobQueue.contains( destinationFileName );
}
- }
- return false;
-}
bool DownloadQueueSet::jobIsWaitingForRetry( QString const & destinationFileName ) const
{
@@ -224,6 +217,37 @@
return pos != m_jobBlackList.constEnd();
}
+
+inline bool DownloadQueueSet::JobStack::contains( const QString& destinationFileName ) const
+{
+ return m_jobsContent.contains( destinationFileName );
}
+inline int DownloadQueueSet::JobStack::count() const
+{
+ return m_jobs.count();
+}
+
+inline bool DownloadQueueSet::JobStack::isEmpty() const
+{
+ return m_jobs.isEmpty();
+}
+
+inline HttpJob * DownloadQueueSet::JobStack::pop()
+{
+ HttpJob * const job = m_jobs.pop();
+ bool const removed = m_jobsContent.remove( job->destinationFileName() );
+ Q_ASSERT( removed );
+ return job;
+}
+
+inline void DownloadQueueSet::JobStack::push( HttpJob * const job )
+{
+ m_jobs.push( job );
+ m_jobsContent.insert( job->destinationFileName() );
+}
+
+
+}
+
#include "DownloadQueueSet.moc"
--- trunk/KDE/kdeedu/marble/src/lib/DownloadQueueSet.h #1121644:1121645
@@ -115,7 +115,19 @@
/** This is the first stage a job enters, from this queue it will get
* into the activatedJobs container.
*/
- QStack<HttpJob*> m_jobQueue;
+ class JobStack
+ {
+ public:
+ bool contains( const QString& destinationFileName ) const;
+ int count() const;
+ bool isEmpty() const;
+ HttpJob * pop();
+ void push( HttpJob * const );
+ private:
+ QStack<HttpJob*> m_jobs;
+ QSet<QString> m_jobsContent;
+ };
+ JobStack m_jobQueue;
/// Contains the jobs which are currently being downloaded.
QList<HttpJob*> m_activeJobs;
More information about the Marble-commits
mailing list