core/transaction: do not call job_is_conflicted_by() twice for the same job
The function searches the list, and it potentially takes O(n). Let's cache the result and avoid duplicated calls. This also rebreaks comments, and rewrites conditions in an equivalent form that is easy to read and matches with the comment above. No functional change, just refactoring.
This commit is contained in:
+18
-24
@@ -163,39 +163,33 @@ static int delete_one_unmergeable_job(Transaction *tr, Job *job) {
|
||||
* drop one of them */
|
||||
if (!j->matters_to_anchor && !k->matters_to_anchor) {
|
||||
|
||||
/* Both jobs don't matter, so let's
|
||||
* find the one that is smarter to
|
||||
* remove. Let's think positive and
|
||||
* rather remove stops then starts --
|
||||
* except if something is being
|
||||
* stopped because it is conflicted by
|
||||
* another unit in which case we
|
||||
* rather remove the start. */
|
||||
/* Both jobs don't matter, so let's find the one that is smarter to remove.
|
||||
* Let's think positive and rather remove stops than starts -- except if
|
||||
* something is being stopped because it is conflicted by another unit in
|
||||
* which case we rather remove the start. */
|
||||
|
||||
bool j_is_conflicted_by = job_is_conflicted_by(j),
|
||||
k_is_conflicted_by = job_is_conflicted_by(k);
|
||||
|
||||
/* Update test/units/TEST-87-AUX-UTILS-VM.sh when logs below are changed. */
|
||||
log_unit_debug(j->unit,
|
||||
"Looking at job %s/%s conflicted_by=%s",
|
||||
j->unit->id, job_type_to_string(j->type),
|
||||
yes_no(j->type == JOB_STOP && job_is_conflicted_by(j)));
|
||||
yes_no(j->type == JOB_STOP && j_is_conflicted_by));
|
||||
log_unit_debug(k->unit,
|
||||
"Looking at job %s/%s conflicted_by=%s",
|
||||
k->unit->id, job_type_to_string(k->type),
|
||||
yes_no(k->type == JOB_STOP && job_is_conflicted_by(k)));
|
||||
yes_no(k->type == JOB_STOP && k_is_conflicted_by));
|
||||
|
||||
if (j->type == JOB_STOP) {
|
||||
|
||||
if (job_is_conflicted_by(j))
|
||||
d = k;
|
||||
else
|
||||
d = j;
|
||||
|
||||
} else if (k->type == JOB_STOP) {
|
||||
|
||||
if (job_is_conflicted_by(k))
|
||||
d = j;
|
||||
else
|
||||
d = k;
|
||||
} else
|
||||
if (j->type == JOB_STOP && j_is_conflicted_by)
|
||||
d = k;
|
||||
else if (k->type == JOB_STOP && k_is_conflicted_by)
|
||||
d = j;
|
||||
else if (j->type == JOB_STOP)
|
||||
d = j;
|
||||
else if (k->type == JOB_STOP)
|
||||
d = k;
|
||||
else
|
||||
d = j;
|
||||
|
||||
} else if (!j->matters_to_anchor)
|
||||
|
||||
Reference in New Issue
Block a user