[v1] libcamera: camera_manager: Simplify camera lookup
diff mbox series

Message ID 20250331150611.523218-1-barnabas.pocze@ideasonboard.com
State Accepted
Headers show
Series
  • [v1] libcamera: camera_manager: Simplify camera lookup
Related show

Commit Message

Barnabás Pőcze March 31, 2025, 3:06 p.m. UTC
`std::find()` works just fine because `std::shared_ptr` has
`operator==()` with the expected semantics.

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

Comments

Laurent Pinchart March 31, 2025, 3:30 p.m. UTC | #1
On Mon, Mar 31, 2025 at 05:06:11PM +0200, Barnabás Pőcze wrote:
> `std::find()` works just fine because `std::shared_ptr` has
> `operator==()` with the expected semantics.
> 
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>

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

> ---
>  src/libcamera/camera_manager.cpp | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp
> index 400109f12..b28bd0bd2 100644
> --- a/src/libcamera/camera_manager.cpp
> +++ b/src/libcamera/camera_manager.cpp
> @@ -239,10 +239,7 @@ void CameraManager::Private::removeCamera(std::shared_ptr<Camera> camera)
>  	{
>  		MutexLocker locker(mutex_);
>  
> -		auto iter = std::find_if(cameras_.begin(), cameras_.end(),
> -					 [camera](std::shared_ptr<Camera> &c) {
> -						 return c.get() == camera.get();
> -					 });
> +		auto iter = std::find(cameras_.begin(), cameras_.end(), camera);
>  		if (iter == cameras_.end())
>  			return;
>
Kieran Bingham March 31, 2025, 4:55 p.m. UTC | #2
Quoting Barnabás Pőcze (2025-03-31 16:06:11)
> `std::find()` works just fine because `std::shared_ptr` has
> `operator==()` with the expected semantics.
> 
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>

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

> ---
>  src/libcamera/camera_manager.cpp | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp
> index 400109f12..b28bd0bd2 100644
> --- a/src/libcamera/camera_manager.cpp
> +++ b/src/libcamera/camera_manager.cpp
> @@ -239,10 +239,7 @@ void CameraManager::Private::removeCamera(std::shared_ptr<Camera> camera)
>         {
>                 MutexLocker locker(mutex_);
>  
> -               auto iter = std::find_if(cameras_.begin(), cameras_.end(),
> -                                        [camera](std::shared_ptr<Camera> &c) {
> -                                                return c.get() == camera.get();
> -                                        });
> +               auto iter = std::find(cameras_.begin(), cameras_.end(), camera);
>                 if (iter == cameras_.end())
>                         return;
>  
> -- 
> 2.49.0
>

Patch
diff mbox series

diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp
index 400109f12..b28bd0bd2 100644
--- a/src/libcamera/camera_manager.cpp
+++ b/src/libcamera/camera_manager.cpp
@@ -239,10 +239,7 @@  void CameraManager::Private::removeCamera(std::shared_ptr<Camera> camera)
 	{
 		MutexLocker locker(mutex_);
 
-		auto iter = std::find_if(cameras_.begin(), cameras_.end(),
-					 [camera](std::shared_ptr<Camera> &c) {
-						 return c.get() == camera.get();
-					 });
+		auto iter = std::find(cameras_.begin(), cameras_.end(), camera);
 		if (iter == cameras_.end())
 			return;