From: Yu Watanabe Date: Sun, 31 Aug 2025 02:01:24 +0000 (+0900) Subject: core/transaction: do not call job_is_conflicted_by() twice for the same job X-Git-Tag: v259-rc1~545^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=59897d86554b060f6bc5ecc4ae393cad768e6b1e;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/core/transaction.c b/src/core/transaction.c index 0f7fe451e7f..be8d43a19b4 100644 --- a/src/core/transaction.c +++ b/src/core/transaction.c @@ -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))); - - if (j->type == JOB_STOP) { - - if (job_is_conflicted_by(j)) - d = k; - else - d = j; + yes_no(k->type == JOB_STOP && k_is_conflicted_by)); - } 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)