[systemd-devel] [PATCH] prioq: avoid to swap item index
Lennart Poettering
lennart at poettering.net
Sun Dec 15 19:57:39 PST 2013
On Mon, 16.12.13 04:48, Lennart Poettering (lennart at poettering.net) wrote:
>
> On Mon, 16.12.13 11:03, Chengwei Yang (chengwei.yang at intel.com) wrote:
>
> > 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.
>
> Sorry, I do understand? Can you elaborate, please? Is this supposed to
^^^^wanted to say: I do *not* understand...
> be a bug fix or an optimization?
>
> > ---
> > 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) {
>
>
> Lennart
>
Lennart
--
Lennart Poettering, Red Hat
More information about the systemd-devel
mailing list