From patchwork Tue Jan 14 18:22:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22568 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 42440C3301 for ; Tue, 14 Jan 2025 18:22:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 09AFB6854E; Tue, 14 Jan 2025 19:22:28 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="gXLkZyTr"; dkim-atps=neutral Received: from mail-10629.protonmail.ch (mail-10629.protonmail.ch [79.135.106.29]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F1D166854C for ; Tue, 14 Jan 2025 19:22:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1736878946; x=1737138146; bh=MNLSu6mkLawqXE/2yDtVn/bcBeJOWkgvPwdl+gHqEfg=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=gXLkZyTrXPi9XEVzL7IKybHegq1RN1oqe6JPtGBdGidkl/V23KEcqncflgpKQocdj AmtD8UOOZZL7YTGh1gYZBnhua2zU5k1Rz9/tQb7/bGlXqExBxYaJSLseHo0MqVdvia iVIQNeRAe2MWsxkHqIy3DVfNDJ4TFEiVN/Z4XTTR2r1liL6tpvnXvgf871an5gMlle /DmvdUF+zVAxTtdD+U/6+dxhohAD12gDsXc5xTyjchYbXd3gs2a45+Z0baqxzXFDkW ESKr/bPBv/eC6TYqfbMNhrmG6LfbOq3R56a4b8FVN6GGXO/qh7pnmYRClln0aLDEm3 gntonyXNhYNGw== Date: Tue, 14 Jan 2025 18:22:22 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: Laurent Pinchart Subject: [RFC PATCH v2 07/16] apps: lc-compliance: Optimize `std::shared_ptr` usage Message-ID: <20250114182143.1773762-8-pobrn@protonmail.com> In-Reply-To: <20250114182143.1773762-1-pobrn@protonmail.com> References: <20250114182143.1773762-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 2f282c01c417d9e32df0d5981dc2dd730a2b16ab MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Avoid unnecessary copies and try to move construct `std::shared_ptr` whenever possible. Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart --- src/apps/lc-compliance/helpers/capture.cpp | 8 ++++---- src/apps/lc-compliance/main.cpp | 4 +--- 2 files changed, 5 insertions(+), 7 deletions(-) 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) - : loop_(nullptr), camera_(camera), - allocator_(std::make_unique(camera)) + : loop_(nullptr), camera_(std::move(camera)), + allocator_(std::make_unique(camera_)) { } @@ -72,7 +72,7 @@ void Capture::stop() /* CaptureBalanced */ CaptureBalanced::CaptureBalanced(std::shared_ptr camera) - : Capture(camera) + : Capture(std::move(camera)) { } @@ -144,7 +144,7 @@ void CaptureBalanced::requestComplete(Request *request) /* CaptureUnbalanced */ CaptureUnbalanced::CaptureUnbalanced(std::shared_ptr 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; - 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 = cm->get(cameraId); if (!camera) { std::cout << "Camera " << cameraId << " not found, available cameras:" << std::endl; listCameras(cm);