[RFC,v1,03/12] apps: lc-compliance: Optimize `std::shared_ptr` usage
diff mbox series

Message ID 20241220150759.709756-4-pobrn@protonmail.com
State New
Headers show
Series
  • apps: lc-compliance: Multi-stream tests
Related show

Commit Message

Barnabás Pőcze Dec. 20, 2024, 3:08 p.m. UTC
Avoid unnecessary copies and try to move construct
`std::shared_ptr` whenever possible.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
---
 src/apps/lc-compliance/helpers/capture.cpp | 8 ++++----
 src/apps/lc-compliance/main.cpp            | 4 +---
 2 files changed, 5 insertions(+), 7 deletions(-)

Patch
diff mbox series

diff --git a/src/apps/lc-compliance/helpers/capture.cpp b/src/apps/lc-compliance/helpers/capture.cpp
index 90c1530ba..d1dafb6cf 100644
--- a/src/apps/lc-compliance/helpers/capture.cpp
+++ b/src/apps/lc-compliance/helpers/capture.cpp
@@ -12,8 +12,8 @@ 
 using namespace libcamera;
 
 Capture::Capture(std::shared_ptr<Camera> camera)
-	: loop_(nullptr), camera_(camera),
-	  allocator_(std::make_unique<FrameBufferAllocator>(camera))
+	: loop_(nullptr), camera_(std::move(camera)),
+	  allocator_(std::make_unique<FrameBufferAllocator>(camera_))
 {
 }
 
@@ -72,7 +72,7 @@  void Capture::stop()
 /* CaptureBalanced */
 
 CaptureBalanced::CaptureBalanced(std::shared_ptr<Camera> camera)
-	: Capture(camera)
+	: Capture(std::move(camera))
 {
 }
 
@@ -144,7 +144,7 @@  void CaptureBalanced::requestComplete(Request *request)
 /* CaptureUnbalanced */
 
 CaptureUnbalanced::CaptureUnbalanced(std::shared_ptr<Camera> camera)
-	: Capture(camera)
+	: Capture(std::move(camera))
 {
 }
 
diff --git a/src/apps/lc-compliance/main.cpp b/src/apps/lc-compliance/main.cpp
index 3f1d2a61b..98f2573d0 100644
--- a/src/apps/lc-compliance/main.cpp
+++ b/src/apps/lc-compliance/main.cpp
@@ -50,8 +50,6 @@  static void listCameras(CameraManager *cm)
 
 static int initCamera(CameraManager *cm, OptionsParser::Options options)
 {
-	std::shared_ptr<Camera> camera;
-
 	int ret = cm->start();
 	if (ret) {
 		std::cout << "Failed to start camera manager: "
@@ -66,7 +64,7 @@  static int initCamera(CameraManager *cm, OptionsParser::Options options)
 	}
 
 	const std::string &cameraId = options[OptCamera];
-	camera = cm->get(cameraId);
+	std::shared_ptr<Camera> camera = cm->get(cameraId);
 	if (!camera) {
 		std::cout << "Camera " << cameraId << " not found, available cameras:" << std::endl;
 		listCameras(cm);