Message ID | 20170328133256.GA24590@singhal-Inspiron-5558 |
---|---|
State | Awaiting Upstream, archived |
Delegated to: | David Miller |
Headers | show |
On Tuesday 2017-03-28 15:32, simran singhal wrote: >This patch replaces ternary operator with macro max as it shorter and >thus increases code readability. > >- return (ret < 0 ? 0 : ret); >+ return max(0, ret); While the two are functionally equivalent, "max" conveys a meaning of "upper bound" (think ceil(3)), i.e. a _count of something_, but the function still returns a logical "error or bool". Such a change may be usable in an IOCCC or a codegolf contest, but it destroys rather than improves readability IMHO.
From: simran singhal > Sent: 28 March 2017 14:33 > This patch replaces ternary operator with macro max as it shorter and > thus increases code readability. Macro max return the maximum of the two > compared values. ... > /* Convert error codes to nomatch */ > - return (ret < 0 ? 0 : ret); > + return max(0, ret); It might be shorter but it isn't more readable. David
diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c index 10a3694..248fef7 100644 --- a/net/netfilter/ipset/ip_set_core.c +++ b/net/netfilter/ipset/ip_set_core.c @@ -571,7 +571,7 @@ ip_set_test(ip_set_id_t index, const struct sk_buff *skb, } /* Convert error codes to nomatch */ - return (ret < 0 ? 0 : ret); + return max(0, ret); } EXPORT_SYMBOL_GPL(ip_set_test);
This patch replaces ternary operator with macro max as it shorter and thus increases code readability. Macro max return the maximum of the two compared values. Signed-off-by: simran singhal <singhalsimran0@gmail.com> --- net/netfilter/ipset/ip_set_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)