lkml.org 
[lkml]   [2016]   [Jun]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH trivial] include/linux/memcontrol.h: Clean up code only

On 6/10/16 01:39, Rik van Riel wrote:
> On Thu, 2016-06-09 at 23:23 +0800, chengang@emindsoft.com.cn wrote:
>> From: Chen Gang <chengang@emindsoft.com.cn>
>>
>> Merge several statements to one return statement, since the new
>> return
>> statement is still simple enough.
>
> This code is not simple, and any change that
> makes it harder to read needs a good reason.
>
> At least in my opinion, your return statement
> merging thing makes the code harder to read.
>

For me, every member has his/her own taste, we need talk about it case
by case.

[...]

>>
>> static inline unsigned short mem_cgroup_id(struct mem_cgroup *memcg)
>> {
>> - if (mem_cgroup_disabled())
>> - return 0;
>> -
>> - return memcg->css.id;
>> + return mem_cgroup_disabled() ? 0 : memcg->css.id;
>> }
>>

For me, this is the simplest way for using "? :", so it is easy enough (
I guess, Linux kernel does not completely reject "? :").

>> /**
>> @@ -341,10 +338,7 @@ static inline unsigned short
>> mem_cgroup_id(struct mem_cgroup *memcg)
>> */
>> static inline struct mem_cgroup *mem_cgroup_from_id(unsigned short
>> id)
>> {
>> - struct cgroup_subsys_state *css;
>> -
>> - css = css_from_id(id, &memory_cgrp_subsys);
>> - return mem_cgroup_from_css(css);
>> + return mem_cgroup_from_css(css_from_id(id, &memory_cgrp_subsys));
>> }
>>

For me, this case may depend on various members' tastes (although it is
simple enough to me -- it is in one line within 80 columns, and related
with 2 functions' call).

For this case, if any of another member suggests to keep original code
no touch, too, I shall send patch v2 for it (keep it no touch).

>> /**
>> @@ -390,9 +384,7 @@ ino_t page_cgroup_ino(struct page *page);
>>
>> static inline bool mem_cgroup_online(struct mem_cgroup *memcg)
>> {
>> - if (mem_cgroup_disabled())
>> - return true;
>> - return !!(memcg->css.flags & CSS_ONLINE);
>> + return mem_cgroup_disabled() || (memcg->css.flags & CSS_ONLINE);
>> }
>>

For me, this is almost the simplest way for using "||", we can find
this case in include/linux (60+ cases for '||', and 150+ for '&&'), and
the new return statement is in one line within 80 columns.

The new return statement is not the simplest, but it is still simple
enough (which should be better than original several lines statements).


Thanks.
--
Chen Gang (陈刚)

Managing Natural Environments is the Duty of Human Beings.

\
 
 \ /
  Last update: 2016-06-10 03:01    [W:0.075 / U:0.508 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site