From patchwork Tue Nov 26 18:03:10 2024 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: 22104 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 19811C3200 for ; Tue, 26 Nov 2024 18:03:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 91D3166083; Tue, 26 Nov 2024 19:03:17 +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="IYaTesip"; dkim-atps=neutral Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0E2EA65FD5 for ; Tue, 26 Nov 2024 19:03:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1732644193; x=1732903393; bh=xdfcfMkSz1GyamSxSaFP82PMdT1VXa2R5IpkYZHvGpA=; h=Date:To:From: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=IYaTesipGQRyjDgphXLUV5KHFVqzo1F3wGGII6ZPyHLOCh1vVwKcaYneZ+mdVyHtn hwMTS6hqir/TOhIyU5++j1E+Qgqhfa8By3d5cQmEBDTjtnKpKmtqI0mm3cLDh5WR+S Kb+RNbbgt4wCx8ojXh9cTDx12ndc3nLLTvJu1RyW2cBExJ6USvt/0ELFgCncwTdcfA mfeR+cruPhmGhI6k7G1ROXjqCA/9vPwbkiwpmd63zoVqr3mfCi98UJAzlTSBNmThsb M2sx1O2Y8c5uPieIjNMO8gsyGLqBojfX256eI0WqpLGjoe5Bc2TitmAuqJulrKgwdB rLaidw7B+uncQ== Date: Tue, 26 Nov 2024 18:03:10 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v1] treewide: Avoid some copies in range-based for loops Message-ID: <20241126180302.685265-2-pobrn@protonmail.com> In-Reply-To: <20241126180302.685265-1-pobrn@protonmail.com> References: <20241126180302.685265-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 74db38cab8dd3493abc5cf2672d3deec339d12c0 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" Most of these have been found by the `performance-for-range-copy` check of `clang-tidy`. Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart --- src/libcamera/camera_manager.cpp | 2 +- src/libcamera/converter.cpp | 5 +++-- src/libcamera/pipeline/virtual/image_frame_generator.cpp | 2 +- src/libcamera/pipeline_handler.cpp | 2 +- test/gstreamer/gstreamer_device_provider_test.cpp | 9 ++------- 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index c7cc5adb..87e6717e 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -388,7 +388,7 @@ std::shared_ptr CameraManager::get(const std::string &id) MutexLocker locker(d->mutex_); - for (std::shared_ptr camera : d->cameras_) { + for (const std::shared_ptr &camera : d->cameras_) { if (camera->id() == id) return camera; } diff --git a/src/libcamera/converter.cpp b/src/libcamera/converter.cpp index 945f2527..3a3f8434 100644 --- a/src/libcamera/converter.cpp +++ b/src/libcamera/converter.cpp @@ -325,8 +325,9 @@ std::vector ConverterFactoryBase::names() for (ConverterFactoryBase *factory : factories) { list.push_back(factory->name_); - for (auto alias : factory->compatibles()) - list.push_back(alias); + + const auto &compatibles = factory->compatibles(); + list.insert(list.end(), compatibles.begin(), compatibles.end()); } return list; diff --git a/src/libcamera/pipeline/virtual/image_frame_generator.cpp b/src/libcamera/pipeline/virtual/image_frame_generator.cpp index 2baef588..277efbb0 100644 --- a/src/libcamera/pipeline/virtual/image_frame_generator.cpp +++ b/src/libcamera/pipeline/virtual/image_frame_generator.cpp @@ -39,7 +39,7 @@ ImageFrameGenerator::create(ImageFrames &imageFrames) * For each file in the directory, load the image, * convert it to NV12, and store the pointer. */ - for (std::filesystem::path path : imageFrames.files) { + for (const auto &path : imageFrames.files) { File file(path); if (!file.open(File::OpenModeFlag::ReadOnly)) { LOG(Virtual, Error) << "Failed to open image file " << file.fileName() diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 991b06f2..caa5c20e 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -74,7 +74,7 @@ PipelineHandler::PipelineHandler(CameraManager *manager) PipelineHandler::~PipelineHandler() { - for (std::shared_ptr media : mediaDevices_) + for (std::shared_ptr &media : mediaDevices_) media->release(); } diff --git a/test/gstreamer/gstreamer_device_provider_test.cpp b/test/gstreamer/gstreamer_device_provider_test.cpp index 8b8e7cba..4b087fcb 100644 --- a/test/gstreamer/gstreamer_device_provider_test.cpp +++ b/test/gstreamer/gstreamer_device_provider_test.cpp @@ -52,17 +52,12 @@ protected: for (l = devices; l != NULL; l = g_list_next(l)) { GstDevice *device = GST_DEVICE(l->data); g_autofree gchar *gst_name; - bool matched = false; g_autoptr(GstElement) element = gst_device_create_element(device, NULL); g_object_get(element, "camera-name", &gst_name, NULL); - for (auto name : cameraNames) { - if (strcmp(name.c_str(), gst_name) == 0) { - matched = true; - break; - } - } + bool matched = + std::find(cameraNames.begin(), cameraNames.end(), gst_name) != cameraNames.end(); if (!matched) return TestFail;