[2/4] elevator: replace continue with else-if in elv_iosched_show

Message ID 852b18c086ef08baec99d08479a3558a3d5db70f.1669391142.git.nickyc975@zju.edu.cn
State New
Headers
Series random improvements and cleanups for elevator.c |

Commit Message

Jinlong Chen Nov. 25, 2022, 3:53 p.m. UTC
  else-if is more readable than continue here.

Signed-off-by: Jinlong Chen <nickyc975@zju.edu.cn>
---
 block/elevator.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
  

Comments

Christoph Hellwig Nov. 29, 2022, 8:33 a.m. UTC | #1
On Fri, Nov 25, 2022 at 11:53:12PM +0800, Jinlong Chen wrote:
>  	list_for_each_entry(e, &elv_list, list) {
> -		if (e == cur) {
> +		if (e == cur)
>  			len += sprintf(name+len, "[%s] ", cur->elevator_name);
> -			continue;
> -		}
> -		if (elv_support_features(q, e))
> +		else if (elv_support_features(q, e))
>  			len += sprintf(name+len, "%s ", e->elevator_name);

Looks good.  But to make this even more obvious I'd also switch to
pinting e->elevator_name for the cur case instead of cur.
  
Jinlong Chen Nov. 29, 2022, 10:51 a.m. UTC | #2
> >  	list_for_each_entry(e, &elv_list, list) {
> > -		if (e == cur) {
> > +		if (e == cur)
> >  			len += sprintf(name+len, "[%s] ", cur->elevator_name);
> > -			continue;
> > -		}
> > -		if (elv_support_features(q, e))
> > +		else if (elv_support_features(q, e))
> >  			len += sprintf(name+len, "%s ", e->elevator_name);
> 
> Looks good.  But to make this even more obvious I'd also switch to
> pinting e->elevator_name for the cur case instead of cur.

That's truely better. I'll send a v2 soon.

Thanks!
Jinlong Chen
  

Patch

diff --git a/block/elevator.c b/block/elevator.c
index 308bee253564..ffa750976d25 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -776,11 +776,9 @@  ssize_t elv_iosched_show(struct request_queue *q, char *name)
 
 	spin_lock(&elv_list_lock);
 	list_for_each_entry(e, &elv_list, list) {
-		if (e == cur) {
+		if (e == cur)
 			len += sprintf(name+len, "[%s] ", cur->elevator_name);
-			continue;
-		}
-		if (elv_support_features(q, e))
+		else if (elv_support_features(q, e))
 			len += sprintf(name+len, "%s ", e->elevator_name);
 	}
 	spin_unlock(&elv_list_lock);