From: Panu Matilainen Date: Wed, 1 Jun 2011 09:40:55 +0000 (+0300) Subject: Eliminate struct copy in collectSCC(), use a pointer instead X-Git-Tag: tznext/4.11.0.1.tizen20130304~1041 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d6787a84894dbf359fd179b16e0302394203736d;p=tools%2Flibrpm-tizen.git Eliminate struct copy in collectSCC(), use a pointer instead - collectSCC() doesn't actually modify the SCC struct it looks at so operating on a copy is harmless, but using a (const) pointer to the original makes the idea more clear (we're not modifying the scc struct here, only its members) --- diff --git a/lib/order.c b/lib/order.c index 0dc50b7..e087ce2 100644 --- a/lib/order.c +++ b/lib/order.c @@ -434,7 +434,7 @@ static void collectSCC(rpm_color_t prefcolor, tsortInfo p_tsi, scc SCCs, tsortInfo * queue_end) { int sccNr = p_tsi->tsi_SccIdx; - struct scc_s SCC = SCCs[sccNr]; + const struct scc_s * SCC = SCCs+sccNr; int i; int start, end; relation rel; @@ -452,15 +452,15 @@ static void collectSCC(rpm_color_t prefcolor, tsortInfo p_tsi, */ /* can use a simple queue as edge weights are always 1 */ - tsortInfo * queue = xmalloc((SCC.size+1) * sizeof(*queue)); + tsortInfo * queue = xmalloc((SCC->size+1) * sizeof(*queue)); /* * Find packages that are prerequired and use them as * starting points for the Dijkstra algorithm */ start = end = 0; - for (i = 0; i < SCC.size; i++) { - tsortInfo tsi = SCC.members[i]; + for (i = 0; i < SCC->size; i++) { + tsortInfo tsi = SCC->members[i]; tsi->tsi_SccLowlink = INT_MAX; for (rel=tsi->tsi_forward_relations; rel != NULL; rel=rel->rel_next) { if (rel->rel_flags && rel->rel_suc->tsi_SccIdx == sccNr) { @@ -476,8 +476,8 @@ static void collectSCC(rpm_color_t prefcolor, tsortInfo p_tsi, } if (start == end) { /* no regular prereqs; add self prereqs to queue */ - for (i = 0; i < SCC.size; i++) { - tsortInfo tsi = SCC.members[i]; + for (i = 0; i < SCC->size; i++) { + tsortInfo tsi = SCC->members[i]; if (tsi->tsi_SccLowlink != INT_MAX) { queue[end++] = tsi; } @@ -505,8 +505,8 @@ static void collectSCC(rpm_color_t prefcolor, tsortInfo p_tsi, int best_score = 0; /* select best candidate to start with */ - for (int i = 0; i < SCC.size; i++) { - tsortInfo tsi = SCC.members[i]; + for (int i = 0; i < SCC->size; i++) { + tsortInfo tsi = SCC->members[i]; if (tsi->tsi_SccIdx == 0) /* package already collected */ continue; if (tsi->tsi_SccLowlink >= best_score) {