From: Michael Schroeder Date: Thu, 8 Dec 2022 12:36:34 +0000 (+0100) Subject: Small code refactoring, no functional changes X-Git-Tag: 0.7.23~15 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3cf0ec93aa0b26dbbdd3f7f3163a74b443e23425;p=thirdparty%2Flibsolv.git Small code refactoring, no functional changes --- diff --git a/src/decision.c b/src/decision.c index 50ff3a95..982eabb1 100644 --- a/src/decision.c +++ b/src/decision.c @@ -379,7 +379,7 @@ solver_get_proof(Solver *solv, Id id, int flags, Queue *q) /* add ruleinfo data to all rules (and also reverse the queue) */ cnt = q->count; - for (i = q->count - 1; i >= 0; i-= 2) + for (i = q->count - 1; i >= 0; i -= 2) { SolverRuleinfo type; Id from = 0, to = 0, dep = 0; @@ -392,14 +392,14 @@ solver_get_proof(Solver *solv, Id id, int flags, Queue *q) if (rid2) type = solver_ruleinfo(solv, rid2, &from, &to, &dep); } - queue_push(q, i > 0 ? q->elements[i - 1] : 0); - queue_push(q, i > 0 ? SOLVER_REASON_UNIT_RULE : SOLVER_REASON_UNSOLVABLE); - queue_push(q, rid); - queue_push(q, 0); /* bits */ - queue_push(q, type); - queue_push(q, from); - queue_push(q, to); - queue_push(q, dep); + queue_insertn(q, q->count, 8, 0); + q->elements[q->count - 8] = i > 0 ? q->elements[i - 1] : 0; + q->elements[q->count - 8 + 1] = i > 0 ? SOLVER_REASON_UNIT_RULE : SOLVER_REASON_UNSOLVABLE; + q->elements[q->count - 8 + 2] = rid; + q->elements[q->count - 8 + 4] = type; + q->elements[q->count - 8 + 5] = from; + q->elements[q->count - 8 + 6] = to; + q->elements[q->count - 8 + 7] = dep; } queue_deleten(q, 0, cnt); @@ -498,7 +498,7 @@ solver_get_proof(Solver *solv, Id id, int flags, Queue *q) } else { - /* set bits */ + /* set decisioninfo bits */ for (i = 0; i < q->count; i += 8) q->elements[i + 3] = solver_calc_decisioninfo_bits(solv, q->elements[i], q->elements[i + 4], q->elements[i + 5], q->elements[i + 6], q->elements[i + 7]); if (flags & SOLVER_DECISIONLIST_MERGEDINFO) @@ -689,7 +689,7 @@ getdecisionlist(Solver *solv, Map *dm, int flags, Queue *decisionlistq) } else { - /* set bits */ + /* set decisioninfo bits */ for (i = 0; i < decisionlistq->count; i += 8) decisionlistq->elements[i + 3] = solver_calc_decisioninfo_bits(solv, decisionlistq->elements[i], decisionlistq->elements[i + 4], decisionlistq->elements[i + 5], decisionlistq->elements[i + 6], decisionlistq->elements[i + 7]); if (flags & SOLVER_DECISIONLIST_MERGEDINFO) @@ -789,6 +789,13 @@ solver_reason2str(Solver *solv, int reason) return "an unknown reason"; } +static const char * +decisionruleinfo2str(Solver *solv, Id decision, int type, Id from, Id to, Id dep) +{ + int bits = solver_calc_decisioninfo_bits(solv, decision, type, from, to, dep); + return solver_decisioninfo2str(solv, bits, type, from, to, dep); +} + const char * solver_decisionreason2str(Solver *solv, Id decision, int reason, Id info) { @@ -797,10 +804,7 @@ solver_decisionreason2str(Solver *solv, Id decision, int reason, Id info) Id from, to, dep; int type = solver_weakdepinfo(solv, decision, &from, &to, &dep); if (type) - { - int bits = solver_calc_decisioninfo_bits(solv, decision, type, from, to, dep); - return solver_decisioninfo2str(solv, bits, type, from, to, dep); - } + return decisionruleinfo2str(solv, decision, type, from, to, dep); } if ((reason == SOLVER_REASON_RESOLVE_JOB || reason == SOLVER_REASON_UNIT_RULE || reason == SOLVER_REASON_RESOLVE || reason == SOLVER_REASON_UNSOLVABLE) && info > 0) { @@ -813,17 +817,11 @@ solver_decisionreason2str(Solver *solv, Id decision, int reason, Id info) { type = solver_ruleinfo(solv, rid2, &from, &to, &dep); if (type) - { - int bits = solver_calc_decisioninfo_bits(solv, decision, type, from, to, dep); - return pool_tmpappend(solv->pool, solver_decisioninfo2str(solv, bits, type, from, to, dep), " (limited)", 0); - } + return decisionruleinfo2str(solv, decision, type, from, to, dep); } } if (type) - { - int bits = solver_calc_decisioninfo_bits(solv, decision, type, from, to, dep); - return solver_decisioninfo2str(solv, bits, type, from, to, dep); - } + return decisionruleinfo2str(solv, decision, type, from, to, dep); } return solver_reason2str(solv, reason); } diff --git a/tools/testsolv.c b/tools/testsolv.c index 572a9ca0..7e6d1985 100644 --- a/tools/testsolv.c +++ b/tools/testsolv.c @@ -111,6 +111,7 @@ showwhy(Solver *solv, const char *showwhypkgstr) /* special case some reasons where we want to show multiple rule infos or extra info */ if (reason == SOLVER_REASON_WEAKDEP || reason == SOLVER_REASON_UNIT_RULE || reason == SOLVER_REASON_RESOLVE) { + queue_empty(&iq); if (reason == SOLVER_REASON_WEAKDEP) solver_allweakdepinfos(solv, v, &iq); else if (info > 0)