]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
reduce number of loops
authorPiotr M <mrow4a@yahoo.com>
Tue, 25 Oct 2016 11:21:03 +0000 (13:21 +0200)
committerPiotr M <mrow4a@yahoo.com>
Mon, 31 Oct 2016 18:45:24 +0000 (19:45 +0100)
src/libsync/owncloudpropagator.cpp
src/libsync/owncloudpropagator.h

index e86532346645fdced15dd65a549ab9e1f1096176..575d72abc2892440e3aaebe2b8a8072a5d387177 100644 (file)
@@ -606,9 +606,15 @@ bool PropagateDirectory::scheduleNextJob()
         return false;
     }
 
+    // cache the value of first unfinished subjob
     bool stopAtDirectory = false;
-    // FIXME: use the cached value of finished job
-    for (int i = 0; i < _subJobs.count(); ++i) {
+    int i = _firstUnfinishedSubJob;
+    int subJobsCount = _subJobs.count();
+    while (i < subJobsCount && _subJobs.at(i)->_state == Finished) {
+      _firstUnfinishedSubJob = ++i;
+    }
+
+    for (int i = _firstUnfinishedSubJob; i < subJobsCount; ++i) {
         if (_subJobs.at(i)->_state == Finished) {
             continue;
         }
index b571e64a633976912c3288338d00dd80f4c3950d..b9862eaafda008989ecd68f23d73ca1775f88eef 100644 (file)
@@ -195,10 +195,11 @@ public:
     int _jobsFinished; // number of jobs that have completed
     int _runningNow; // number of subJobs running right now
     SyncFileItem::Status _hasError;  // NoStatus,  or NormalError / SoftError if there was an error
+    int _firstUnfinishedSubJob;
 
     explicit PropagateDirectory(OwncloudPropagator *propagator, const SyncFileItemPtr &item = SyncFileItemPtr(new SyncFileItem))
         : PropagatorJob(propagator)
-        , _firstJob(0), _item(item),  _jobsFinished(0), _runningNow(0), _hasError(SyncFileItem::NoStatus)
+        , _firstJob(0), _item(item),  _jobsFinished(0), _runningNow(0), _hasError(SyncFileItem::NoStatus), _firstUnfinishedSubJob(0)
     { }
 
     virtual ~PropagateDirectory() {