Skip to content

Commit

Permalink
reduce number of loops
Browse files Browse the repository at this point in the history
  • Loading branch information
mrow4a committed Oct 31, 2016
1 parent cf48ea2 commit 34c59ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/libsync/owncloudpropagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/libsync/owncloudpropagator.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,11 @@ class OWNCLOUDSYNC_EXPORT PropagateDirectory : public PropagatorJob {
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() {
Expand Down

0 comments on commit 34c59ba

Please sign in to comment.