[libcalamares] Refactor job-weight computations

- only check index-vs-length once
This commit is contained in:
Adriaan de Groot 2020-03-16 17:25:27 +01:00
parent 07da6e3905
commit afc0c78b4c

View File

@ -73,7 +73,8 @@ public:
}
emitProgress();
cDebug() << "Starting" << ( anyFailed ? "EMERGENCY JOB" : "job" ) << job->prettyName() << " (there are" << m_jobs.count() << " left)";
cDebug() << "Starting" << ( anyFailed ? "EMERGENCY JOB" : "job" ) << job->prettyName() << " (there are"
<< m_jobs.count() << " left)";
connect( job.data(), &Job::progress, this, &JobThread::emitProgress );
JobResult result = job->exec();
if ( !anyFailed && !result )
@ -113,20 +114,20 @@ private:
int jobCount = m_jobs.size();
QString message = m_jobIndex < jobCount ? m_jobs.at( m_jobIndex )->prettyStatusMessage() : tr( "Done" );
qreal percent = 1.0; // Pretend we're done, since the if will reset it
if ( m_jobIndex < jobCount )
{
qreal cumulativeProgress = 0.0;
for ( auto jobWeight : m_jobWeights.mid( 0, m_jobIndex ) )
{
cumulativeProgress += jobWeight;
}
qreal percent
= m_jobIndex < jobCount ? cumulativeProgress + ( ( m_jobWeights.at( m_jobIndex ) ) * jobPercent ) : 1.0;
percent = cumulativeProgress + ( ( m_jobWeights.at( m_jobIndex ) ) * jobPercent );
if ( m_jobIndex < jobCount )
{
Logger::CDebug( Logger::LOGVERBOSE ) << "[JOBQUEUE]: Progress for Job[" << m_jobIndex
<< "]: " << ( jobPercent * 100 ) << "% completed";
Logger::CDebug( Logger::LOGVERBOSE ) << "[JOBQUEUE]: Progress Overall: " << ( cumulativeProgress * 100 )
<< "% (accumulated) + "
Logger::CDebug( Logger::LOGVERBOSE )
<< "[JOBQUEUE]: Progress for Job[" << m_jobIndex << "]: " << ( jobPercent * 100 ) << "% completed";
Logger::CDebug( Logger::LOGVERBOSE )
<< "[JOBQUEUE]: Progress Overall: " << ( cumulativeProgress * 100 ) << "% (accumulated) + "
<< ( ( ( m_jobWeights.at( m_jobIndex ) ) * jobPercent ) * 100 )
<< "% (this job) = " << ( percent * 100 ) << "% (total)";
}