* [PATCH] staging: comedi: Optimize code using logical short-circuiting
@ 2016-09-16 19:24 Namrata A Shettar
2016-09-17 18:35 ` Greg Kroah-Hartman
0 siblings, 1 reply; 3+ messages in thread
From: Namrata A Shettar @ 2016-09-16 19:24 UTC (permalink / raw)
To: outreachy-kernel, Ian Abbott, H Hartley Sweeten,
Greg Kroah-Hartman, Leslie Klein
Optimize code using logical short-circuiting. Two if statements
having same return value is equivalent to a single if statement with
condition being the union of the prior two.
Signed-off-by: Namrata A Shettar <namrataashettar@gmail.com>
---
drivers/staging/comedi/comedi_fops.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index 1999eed..0d69ed7 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -791,9 +791,7 @@ static int is_device_busy(struct comedi_device *dev)
for (i = 0; i < dev->n_subdevices; i++) {
s = &dev->subdevices[i];
- if (s->busy)
- return 1;
- if (s->async && comedi_buf_is_mmapped(s))
+ if (s->busy || (s->async && comedi_buf_is_mmapped(s)))
return 1;
}
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] staging: comedi: Optimize code using logical short-circuiting
2016-09-16 19:24 [PATCH] staging: comedi: Optimize code using logical short-circuiting Namrata A Shettar
@ 2016-09-17 18:35 ` Greg Kroah-Hartman
2016-09-18 4:44 ` Namrata A Shettar
0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2016-09-17 18:35 UTC (permalink / raw)
To: Namrata A Shettar
Cc: outreachy-kernel, Ian Abbott, H Hartley Sweeten, Leslie Klein
On Sat, Sep 17, 2016 at 12:54:59AM +0530, Namrata A Shettar wrote:
> Optimize code using logical short-circuiting. Two if statements
> having same return value is equivalent to a single if statement with
> condition being the union of the prior two.
>
> Signed-off-by: Namrata A Shettar <namrataashettar@gmail.com>
> ---
> drivers/staging/comedi/comedi_fops.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
> index 1999eed..0d69ed7 100644
> --- a/drivers/staging/comedi/comedi_fops.c
> +++ b/drivers/staging/comedi/comedi_fops.c
> @@ -791,9 +791,7 @@ static int is_device_busy(struct comedi_device *dev)
>
> for (i = 0; i < dev->n_subdevices; i++) {
> s = &dev->subdevices[i];
> - if (s->busy)
> - return 1;
> - if (s->async && comedi_buf_is_mmapped(s))
> + if (s->busy || (s->async && comedi_buf_is_mmapped(s)))
> return 1;
The original code was easier to read.
We write kernel code for developers first, and the compiler second. In
either case, the compiler will create the same output, you haven't
really saved any logic or speed here. You have made it harder to read
and follow, so I will have to reject this change, sorry.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] staging: comedi: Optimize code using logical short-circuiting
2016-09-17 18:35 ` Greg Kroah-Hartman
@ 2016-09-18 4:44 ` Namrata A Shettar
0 siblings, 0 replies; 3+ messages in thread
From: Namrata A Shettar @ 2016-09-18 4:44 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: outreachy-kernel, Ian Abbott, H Hartley Sweeten, Leslie Klein
On Sat, Sep 17, 2016 at 08:35:22PM +0200, Greg Kroah-Hartman wrote:
> On Sat, Sep 17, 2016 at 12:54:59AM +0530, Namrata A Shettar wrote:
> > Optimize code using logical short-circuiting. Two if statements
> > having same return value is equivalent to a single if statement with
> > condition being the union of the prior two.
> >
> > Signed-off-by: Namrata A Shettar <namrataashettar@gmail.com>
> > ---
> > drivers/staging/comedi/comedi_fops.c | 4 +---
> > 1 file changed, 1 insertion(+), 3 deletions(-)
> >
> > diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
> > index 1999eed..0d69ed7 100644
> > --- a/drivers/staging/comedi/comedi_fops.c
> > +++ b/drivers/staging/comedi/comedi_fops.c
> > @@ -791,9 +791,7 @@ static int is_device_busy(struct comedi_device *dev)
> >
> > for (i = 0; i < dev->n_subdevices; i++) {
> > s = &dev->subdevices[i];
> > - if (s->busy)
> > - return 1;
> > - if (s->async && comedi_buf_is_mmapped(s))
> > + if (s->busy || (s->async && comedi_buf_is_mmapped(s)))
> > return 1;
>
> The original code was easier to read.
>
> We write kernel code for developers first, and the compiler second. In
> either case, the compiler will create the same output, you haven't
> really saved any logic or speed here. You have made it harder to read
> and follow, so I will have to reject this change, sorry.
>
> thanks,
>
> greg k-h
Got that! will keep that in mind the next time around I plan making such
a change.
thanks,
namrata
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-09-18 4:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-16 19:24 [PATCH] staging: comedi: Optimize code using logical short-circuiting Namrata A Shettar
2016-09-17 18:35 ` Greg Kroah-Hartman
2016-09-18 4:44 ` Namrata A Shettar
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.