[v1] apps: qcam: Simplify `PixelFormat` search
diff mbox series

Message ID 20250303193339.785634-1-barnabas.pocze@ideasonboard.com
State Accepted
Headers show
Series
  • [v1] apps: qcam: Simplify `PixelFormat` search
Related show

Commit Message

Barnabás Pőcze March 3, 2025, 7:33 p.m. UTC
Since `PixelFormat` has `operator==()`, `std::find()` can be used
directly, so do that to simplify.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
 src/apps/qcam/main_window.cpp | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

Comments

Laurent Pinchart March 3, 2025, 8:59 p.m. UTC | #1
Hi Barnabás,

Thank you for the patch.

On Mon, Mar 03, 2025 at 08:33:39PM +0100, Barnabás Pőcze wrote:
> Since `PixelFormat` has `operator==()`, `std::find()` can be used
> directly, so do that to simplify.
> 
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  src/apps/qcam/main_window.cpp | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/src/apps/qcam/main_window.cpp b/src/apps/qcam/main_window.cpp
> index 3880a846e..d2ccbd231 100644
> --- a/src/apps/qcam/main_window.cpp
> +++ b/src/apps/qcam/main_window.cpp
> @@ -386,10 +386,7 @@ int MainWindow::startCapture()
>  	/* Use a format supported by the viewfinder if available. */
>  	std::vector<PixelFormat> formats = vfConfig.formats().pixelformats();
>  	for (const PixelFormat &format : viewfinder_->nativeFormats()) {
> -		auto match = std::find_if(formats.begin(), formats.end(),
> -					  [&](const PixelFormat &f) {
> -						  return f == format;
> -					  });
> +		auto match = std::find(formats.begin(), formats.end(), format);
>  		if (match != formats.end()) {
>  			vfConfig.pixelFormat = format;
>  			break;
Kieran Bingham March 4, 2025, 10:05 a.m. UTC | #2
Quoting Barnabás Pőcze (2025-03-03 19:33:39)
> Since `PixelFormat` has `operator==()`, `std::find()` can be used
> directly, so do that to simplify.
> 
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>

I'm curious if this was possible when the auto match was added in the
first place, or if the operator==() came later, but either way - no need
to go into archeology for this so:


Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> ---
>  src/apps/qcam/main_window.cpp | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/src/apps/qcam/main_window.cpp b/src/apps/qcam/main_window.cpp
> index 3880a846e..d2ccbd231 100644
> --- a/src/apps/qcam/main_window.cpp
> +++ b/src/apps/qcam/main_window.cpp
> @@ -386,10 +386,7 @@ int MainWindow::startCapture()
>         /* Use a format supported by the viewfinder if available. */
>         std::vector<PixelFormat> formats = vfConfig.formats().pixelformats();
>         for (const PixelFormat &format : viewfinder_->nativeFormats()) {
> -               auto match = std::find_if(formats.begin(), formats.end(),
> -                                         [&](const PixelFormat &f) {
> -                                                 return f == format;
> -                                         });
> +               auto match = std::find(formats.begin(), formats.end(), format);
>                 if (match != formats.end()) {
>                         vfConfig.pixelFormat = format;
>                         break;
> -- 
> 2.48.1
>

Patch
diff mbox series

diff --git a/src/apps/qcam/main_window.cpp b/src/apps/qcam/main_window.cpp
index 3880a846e..d2ccbd231 100644
--- a/src/apps/qcam/main_window.cpp
+++ b/src/apps/qcam/main_window.cpp
@@ -386,10 +386,7 @@  int MainWindow::startCapture()
 	/* Use a format supported by the viewfinder if available. */
 	std::vector<PixelFormat> formats = vfConfig.formats().pixelformats();
 	for (const PixelFormat &format : viewfinder_->nativeFormats()) {
-		auto match = std::find_if(formats.begin(), formats.end(),
-					  [&](const PixelFormat &f) {
-						  return f == format;
-					  });
+		auto match = std::find(formats.begin(), formats.end(), format);
 		if (match != formats.end()) {
 			vfConfig.pixelFormat = format;
 			break;