mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Colin Ian King <colin.king@canonical.com>
To: Markus Elfring <Markus.Elfring@web.de>,
	kernel-janitors@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Arnd Bergmann <arnd@arndb.de>,
	Davidlohr Bueso <dave@stgolabs.net>,
	"Gustavo A. R. Silva" <gustavo@embeddedor.com>,
	Manfred Spraul <manfred@colorfullife.com>,
	Mathieu Malaterre <malat@debian.org>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] ipc/sem: Three function calls less in do_semtimedop()
Date: Sat, 6 Jul 2019 21:13:46 +0100	[thread overview]
Message-ID: <3c5d5941-63bf-5576-e6eb-17ca02a6a8a3@canonical.com> (raw)
In-Reply-To: <ba328a83-63ac-c3a3-cbc0-81059012c555@web.de>

On 06/07/2019 13:28, Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 6 Jul 2019 14:16:24 +0200
> 
> Avoid three function calls by using ternary operators instead of
> conditional statements.
> 
> This issue was detected by using the Coccinelle software.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  ipc/sem.c | 25 ++++++++-----------------
>  1 file changed, 8 insertions(+), 17 deletions(-)
> 
> diff --git a/ipc/sem.c b/ipc/sem.c
> index 7da4504bcc7c..56ea549ac270 100644
> --- a/ipc/sem.c
> +++ b/ipc/sem.c
> @@ -2122,27 +2122,18 @@ static long do_semtimedop(int semid, struct sembuf __user *tsops,
>  		int idx = array_index_nospec(sops->sem_num, sma->sem_nsems);
>  		curr = &sma->sems[idx];
> 
> -		if (alter) {
> -			if (sma->complex_count) {
> -				list_add_tail(&queue.list,
> -						&sma->pending_alter);
> -			} else {
> -
> -				list_add_tail(&queue.list,
> -						&curr->pending_alter);
> -			}
> -		} else {
> -			list_add_tail(&queue.list, &curr->pending_const);
> -		}
> +		list_add_tail(&queue.list,
> +			      alter
> +			      ? (sma->complex_count
> +				? &sma->pending_alter
> +				: &curr->pending_alter)
> +			      : &curr->pending_const);

Just no. This is making the code harder to comprehend with no advantage.
Compilers are smart, let the do the optimization work and keep code
simple for us mere mortals.

Colin

>  	} else {
>  		if (!sma->complex_count)
>  			merge_queues(sma);
> 
> -		if (alter)
> -			list_add_tail(&queue.list, &sma->pending_alter);
> -		else
> -			list_add_tail(&queue.list, &sma->pending_const);
> -
> +		list_add_tail(&queue.list,
> +			      alter ? &sma->pending_alter : &sma->pending_const);
>  		sma->complex_count++;
>  	}
> 
> --
> 2.22.0
> 


  reply	other threads:[~2019-07-06 20:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-06 12:28 Markus Elfring
2019-07-06 20:13 ` Colin Ian King [this message]
2019-07-06 20:50   ` Al Viro
2019-07-07  7:09   ` Markus Elfring

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=3c5d5941-63bf-5576-e6eb-17ca02a6a8a3@canonical.com \
    --to=colin.king@canonical.com \
    --cc=Markus.Elfring@web.de \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=dave@stgolabs.net \
    --cc=gustavo@embeddedor.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=malat@debian.org \
    --cc=manfred@colorfullife.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