[systemd-devel] [PATCH] prioq: avoid to swap item index

Chengwei Yang chengwei.yang at intel.com
Sun Dec 15 19:03:18 PST 2013


the swap() operation of prioq which in fact only swap item's data but
keep idx untouched. However, current implement does first swap the idx
and then swap back again.
---
 src/shared/prioq.c |   10 ----------
 1 file changed, 10 deletions(-)

diff --git a/src/shared/prioq.c b/src/shared/prioq.c
index 8af4c51..ef99c47 100644
--- a/src/shared/prioq.c
+++ b/src/shared/prioq.c
@@ -68,7 +68,6 @@ int prioq_ensure_allocated(Prioq **q, compare_func_t compare_func) {
 
 static void swap(Prioq *q, unsigned j, unsigned k) {
         void *saved_data;
-        unsigned *saved_idx;
 
         assert(q);
         assert(j < q->n_items);
@@ -78,17 +77,8 @@ static void swap(Prioq *q, unsigned j, unsigned k) {
         assert(!q->items[k].idx || *(q->items[k].idx) == k);
 
         saved_data = q->items[j].data;
-        saved_idx = q->items[j].idx;
         q->items[j].data = q->items[k].data;
-        q->items[j].idx = q->items[k].idx;
         q->items[k].data = saved_data;
-        q->items[k].idx = saved_idx;
-
-        if (q->items[j].idx)
-                *q->items[j].idx = j;
-
-        if (q->items[k].idx)
-                *q->items[k].idx = k;
 }
 
 static unsigned shuffle_up(Prioq *q, unsigned idx) {
-- 
1.7.9.5



More information about the systemd-devel mailing list