mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Yong Zhi <yong.zhi@intel.com>, Bingbu Cao <bingbu.cao@intel.com>,
	Dan Scally <djrscally@gmail.com>,
	Tianshu Qiu <tian.shu.qiu@intel.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>
Subject: [PATCH v1 1/3] lib/sort: Split out choose_swap_func() local helper
Date: Tue, 24 Aug 2021 16:33:49 +0300	[thread overview]
Message-ID: <20210824133351.88179-1-andriy.shevchenko@linux.intel.com> (raw)

In some new code we may need the same functionality as provided by
newly introduced choose_swap_func() helper.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 lib/sort.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/lib/sort.c b/lib/sort.c
index aa18153864d2..d9b2f5b73620 100644
--- a/lib/sort.c
+++ b/lib/sort.c
@@ -151,6 +151,18 @@ static int do_cmp(const void *a, const void *b, cmp_r_func_t cmp, const void *pr
 	return cmp(a, b, priv);
 }
 
+static swap_func_t choose_swap_func(swap_func_t swap_func, void *base, size_t size)
+{
+	if (swap_func)
+		return swap_func;
+
+	if (is_aligned(base, size, 8))
+		return SWAP_WORDS_64;
+	if (is_aligned(base, size, 4))
+		return SWAP_WORDS_32;
+	return SWAP_BYTES;
+}
+
 /**
  * parent - given the offset of the child, find the offset of the parent.
  * @i: the offset of the heap element whose parent is sought.  Non-zero.
@@ -208,14 +220,7 @@ void sort_r(void *base, size_t num, size_t size,
 	if (!a)		/* num < 2 || size == 0 */
 		return;
 
-	if (!swap_func) {
-		if (is_aligned(base, size, 8))
-			swap_func = SWAP_WORDS_64;
-		else if (is_aligned(base, size, 4))
-			swap_func = SWAP_WORDS_32;
-		else
-			swap_func = SWAP_BYTES;
-	}
+	swap_func = choose_swap_func(swap_func, base, size);
 
 	/*
 	 * Loop invariants:
-- 
2.32.0


             reply	other threads:[~2021-08-24 13:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-24 13:33 Andy Shevchenko [this message]
2021-08-24 13:33 ` [PATCH v1 2/3] lib/sort: Introduce rotate() to circular shift an array of elements Andy Shevchenko
2021-08-25  7:05   ` Rasmus Villemoes
2021-08-25  8:08     ` Sakari Ailus
2021-08-25  9:29       ` Rasmus Villemoes
2021-08-25  9:55         ` Andy Shevchenko
2021-08-24 13:33 ` [RFT, PATCH v1 3/3] media: ipu3-cio2: Replace custom implementation of rotate() Andy Shevchenko
2021-08-25  8:00 ` [PATCH v1 1/3] lib/sort: Split out choose_swap_func() local helper Sakari Ailus

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=20210824133351.88179-1-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=bingbu.cao@intel.com \
    --cc=djrscally@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab+huawei@kernel.org \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=tian.shu.qiu@intel.com \
    --cc=yong.zhi@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome