linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fbcon: break earlier in search_fb_in_map and search_for_mapped_con
@ 2024-09-26 11:59 Qianqiang Liu
  2024-09-26 16:25 ` Helge Deller
  2024-09-29 19:45 ` Andy Shevchenko
  0 siblings, 2 replies; 3+ messages in thread
From: Qianqiang Liu @ 2024-09-26 11:59 UTC (permalink / raw)
  To: deller; +Cc: linux-fbdev, dri-devel, linux-kernel, Qianqiang Liu

Break the for loop immediately upon finding the target, making the
process more efficient.

Signed-off-by: Qianqiang Liu <qianqiang.liu@163.com>
---
 drivers/video/fbdev/core/fbcon.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c
index d9abae2516d8..e8b4e8c119b5 100644
--- a/drivers/video/fbdev/core/fbcon.c
+++ b/drivers/video/fbdev/core/fbcon.c
@@ -512,8 +512,10 @@ static int search_fb_in_map(int idx)
 	int i, retval = 0;
 
 	for (i = first_fb_vc; i <= last_fb_vc; i++) {
-		if (con2fb_map[i] == idx)
+		if (con2fb_map[i] == idx) {
 			retval = 1;
+			break;
+		}
 	}
 	return retval;
 }
@@ -523,8 +525,10 @@ static int search_for_mapped_con(void)
 	int i, retval = 0;
 
 	for (i = first_fb_vc; i <= last_fb_vc; i++) {
-		if (con2fb_map[i] != -1)
+		if (con2fb_map[i] != -1) {
 			retval = 1;
+			break;
+		}
 	}
 	return retval;
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] fbcon: break earlier in search_fb_in_map and search_for_mapped_con
  2024-09-26 11:59 [PATCH] fbcon: break earlier in search_fb_in_map and search_for_mapped_con Qianqiang Liu
@ 2024-09-26 16:25 ` Helge Deller
  2024-09-29 19:45 ` Andy Shevchenko
  1 sibling, 0 replies; 3+ messages in thread
From: Helge Deller @ 2024-09-26 16:25 UTC (permalink / raw)
  To: Qianqiang Liu; +Cc: linux-fbdev, dri-devel, linux-kernel

On 9/26/24 13:59, Qianqiang Liu wrote:
> Break the for loop immediately upon finding the target, making the
> process more efficient.
>
> Signed-off-by: Qianqiang Liu <qianqiang.liu@163.com>

applied.

Thanks!
Helge

> ---
>   drivers/video/fbdev/core/fbcon.c | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c
> index d9abae2516d8..e8b4e8c119b5 100644
> --- a/drivers/video/fbdev/core/fbcon.c
> +++ b/drivers/video/fbdev/core/fbcon.c
> @@ -512,8 +512,10 @@ static int search_fb_in_map(int idx)
>   	int i, retval = 0;
>
>   	for (i = first_fb_vc; i <= last_fb_vc; i++) {
> -		if (con2fb_map[i] == idx)
> +		if (con2fb_map[i] == idx) {
>   			retval = 1;
> +			break;
> +		}
>   	}
>   	return retval;
>   }
> @@ -523,8 +525,10 @@ static int search_for_mapped_con(void)
>   	int i, retval = 0;
>
>   	for (i = first_fb_vc; i <= last_fb_vc; i++) {
> -		if (con2fb_map[i] != -1)
> +		if (con2fb_map[i] != -1) {
>   			retval = 1;
> +			break;
> +		}
>   	}
>   	return retval;
>   }


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] fbcon: break earlier in search_fb_in_map and search_for_mapped_con
  2024-09-26 11:59 [PATCH] fbcon: break earlier in search_fb_in_map and search_for_mapped_con Qianqiang Liu
  2024-09-26 16:25 ` Helge Deller
@ 2024-09-29 19:45 ` Andy Shevchenko
  1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2024-09-29 19:45 UTC (permalink / raw)
  To: Qianqiang Liu; +Cc: deller, linux-fbdev, dri-devel, linux-kernel

Thu, Sep 26, 2024 at 07:59:11PM +0800, Qianqiang Liu kirjoitti:
> Break the for loop immediately upon finding the target, making the
> process more efficient.

You may make it even more effecient (in terms of code readability as I believe
compiler optimizes this anyway to the same):

>  	int i, retval = 0;
>  
>  	for (i = first_fb_vc; i <= last_fb_vc; i++) {
> -		if (con2fb_map[i] == idx)
> +		if (con2fb_map[i] == idx) {
>  			retval = 1;
> +			break;
> +		}

		return 1;

>  	}
>  	return retval;

	return 0;

>  }

...

>  	int i, retval = 0;
>  
>  	for (i = first_fb_vc; i <= last_fb_vc; i++) {
> -		if (con2fb_map[i] != -1)
> +		if (con2fb_map[i] != -1) {
>  			retval = 1;
> +			break;
> +		}
>  	}
>  	return retval;

Ditto.

...

Since it's applied, you can consider a followup.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-09-29 19:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-26 11:59 [PATCH] fbcon: break earlier in search_fb_in_map and search_for_mapped_con Qianqiang Liu
2024-09-26 16:25 ` Helge Deller
2024-09-29 19:45 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).