All of lore.kernel.org
 help / color / mirror / Atom feed
From: Clemens Ladisch <clemens@ladisch.de>
To: Steven Whitehouse <swhiteho@redhat.com>
Cc: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>,
	Don Mullis <don.mullis@gmail.com>,
	Dave Chinner <david@fromorbit.com>,
	linux-kernel@vger.kernel.org
Subject: Re: list sort
Date: Wed, 27 Jul 2011 16:45:55 +0200	[thread overview]
Message-ID: <4E3024A3.7010102@ladisch.de> (raw)
In-Reply-To: <1311773014.2801.23.camel@menhir>

Steven Whitehouse wrote:
> There seems to be an issue with list_sort trying to compare an object to
> itself. [...]
> While it appears generally harmless, since the list does appear to be
> correctly sorted, it is doing extra work needlessly.

There are sort algorithms where this happens naturally, and adding
an additional check to avoid calling the comparison function when the
pointers are equal would be more work overall than just calling cmp().

This does not happen with list_sort()'s merge sort, but I've noticed
the following hack in merge_and_restore_back_links():

	do {
		/*
		 * In worst cases this loop may run many iterations.
		 * Continue callbacks to the client even though no
		 * element comparison is needed, so the client's cmp()
		 * routine can invoke cond_resched() periodically.
		 */
		(*cmp)(priv, tail->next, tail->next);

		tail->next->prev = tail;
		tail = tail->next;
	} while (tail->next);

When there is no cond_resched() call, this is indeed needless work.

However, if the list is so short that cond_resched() is not needed,
the additional comparisons should not hurt anyway.


Regards,
Clemens

  reply	other threads:[~2011-07-27 14:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-27 13:23 list sort Steven Whitehouse
2011-07-27 14:45 ` Clemens Ladisch [this message]
2011-07-27 15:04   ` Steven Whitehouse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E3024A3.7010102@ladisch.de \
    --to=clemens@ladisch.de \
    --cc=Artem.Bityutskiy@nokia.com \
    --cc=david@fromorbit.com \
    --cc=don.mullis@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=swhiteho@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.