Patch Detail
Show a patch.
GET /api/patches/22104/?format=api
{ "id": 22104, "url": "https://patchwork.libcamera.org/api/patches/22104/?format=api", "web_url": "https://patchwork.libcamera.org/patch/22104/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20241126180302.685265-2-pobrn@protonmail.com>", "date": "2024-11-26T18:03:10", "name": "[v1] treewide: Avoid some copies in range-based for loops", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "ac1ea39251a7ac7df37fba214522985500082113", "submitter": { "id": 133, "url": "https://patchwork.libcamera.org/api/people/133/?format=api", "name": "Pőcze Barnabás", "email": "pobrn@protonmail.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/22104/mbox/", "series": [ { "id": 4825, "url": "https://patchwork.libcamera.org/api/series/4825/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4825", "date": "2024-11-26T18:03:10", "name": "[v1] treewide: Avoid some copies in range-based for loops", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4825/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/22104/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/22104/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 19811C3200\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 26 Nov 2024 18:03:19 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 91D3166083;\n\tTue, 26 Nov 2024 19:03:17 +0100 (CET)", "from mail-4322.protonmail.ch (mail-4322.protonmail.ch\n\t[185.70.43.22])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0E2EA65FD5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 26 Nov 2024 19:03:14 +0100 (CET)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=protonmail.com header.i=@protonmail.com\n\theader.b=\"IYaTesip\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;\n\ts=protonmail3; t=1732644193; x=1732903393;\n\tbh=xdfcfMkSz1GyamSxSaFP82PMdT1VXa2R5IpkYZHvGpA=;\n\th=Date:To:From:Subject:Message-ID:In-Reply-To:References:\n\tFeedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID:\n\tMessage-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post;\n\tb=IYaTesipGQRyjDgphXLUV5KHFVqzo1F3wGGII6ZPyHLOCh1vVwKcaYneZ+mdVyHtn\n\thwMTS6hqir/TOhIyU5++j1E+Qgqhfa8By3d5cQmEBDTjtnKpKmtqI0mm3cLDh5WR+S\n\tKb+RNbbgt4wCx8ojXh9cTDx12ndc3nLLTvJu1RyW2cBExJ6USvt/0ELFgCncwTdcfA\n\tmfeR+cruPhmGhI6k7G1ROXjqCA/9vPwbkiwpmd63zoVqr3mfCi98UJAzlTSBNmThsb\n\tM2sx1O2Y8c5uPieIjNMO8gsyGLqBojfX256eI0WqpLGjoe5Bc2TitmAuqJulrKgwdB\n\trLaidw7B+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?= <pobrn@protonmail.com>", "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", "Content-Type": "text/plain; charset=utf-8", "Content-Transfer-Encoding": "quoted-printable", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Most of these have been found by the `performance-for-range-copy`\ncheck of `clang-tidy`.\n\nSigned-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n---\n src/libcamera/camera_manager.cpp | 2 +-\n src/libcamera/converter.cpp | 5 +++--\n src/libcamera/pipeline/virtual/image_frame_generator.cpp | 2 +-\n src/libcamera/pipeline_handler.cpp | 2 +-\n test/gstreamer/gstreamer_device_provider_test.cpp | 9 ++-------\n 5 files changed, 8 insertions(+), 12 deletions(-)", "diff": "diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp\nindex c7cc5adb..87e6717e 100644\n--- a/src/libcamera/camera_manager.cpp\n+++ b/src/libcamera/camera_manager.cpp\n@@ -388,7 +388,7 @@ std::shared_ptr<Camera> CameraManager::get(const std::string &id)\n \n \tMutexLocker locker(d->mutex_);\n \n-\tfor (std::shared_ptr<Camera> camera : d->cameras_) {\n+\tfor (const std::shared_ptr<Camera> &camera : d->cameras_) {\n \t\tif (camera->id() == id)\n \t\t\treturn camera;\n \t}\ndiff --git a/src/libcamera/converter.cpp b/src/libcamera/converter.cpp\nindex 945f2527..3a3f8434 100644\n--- a/src/libcamera/converter.cpp\n+++ b/src/libcamera/converter.cpp\n@@ -325,8 +325,9 @@ std::vector<std::string> ConverterFactoryBase::names()\n \n \tfor (ConverterFactoryBase *factory : factories) {\n \t\tlist.push_back(factory->name_);\n-\t\tfor (auto alias : factory->compatibles())\n-\t\t\tlist.push_back(alias);\n+\n+\t\tconst auto &compatibles = factory->compatibles();\n+\t\tlist.insert(list.end(), compatibles.begin(), compatibles.end());\n \t}\n \n \treturn list;\ndiff --git a/src/libcamera/pipeline/virtual/image_frame_generator.cpp b/src/libcamera/pipeline/virtual/image_frame_generator.cpp\nindex 2baef588..277efbb0 100644\n--- a/src/libcamera/pipeline/virtual/image_frame_generator.cpp\n+++ b/src/libcamera/pipeline/virtual/image_frame_generator.cpp\n@@ -39,7 +39,7 @@ ImageFrameGenerator::create(ImageFrames &imageFrames)\n \t * For each file in the directory, load the image,\n \t * convert it to NV12, and store the pointer.\n \t */\n-\tfor (std::filesystem::path path : imageFrames.files) {\n+\tfor (const auto &path : imageFrames.files) {\n \t\tFile file(path);\n \t\tif (!file.open(File::OpenModeFlag::ReadOnly)) {\n \t\t\tLOG(Virtual, Error) << \"Failed to open image file \" << file.fileName()\ndiff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp\nindex 991b06f2..caa5c20e 100644\n--- a/src/libcamera/pipeline_handler.cpp\n+++ b/src/libcamera/pipeline_handler.cpp\n@@ -74,7 +74,7 @@ PipelineHandler::PipelineHandler(CameraManager *manager)\n \n PipelineHandler::~PipelineHandler()\n {\n-\tfor (std::shared_ptr<MediaDevice> media : mediaDevices_)\n+\tfor (std::shared_ptr<MediaDevice> &media : mediaDevices_)\n \t\tmedia->release();\n }\n \ndiff --git a/test/gstreamer/gstreamer_device_provider_test.cpp b/test/gstreamer/gstreamer_device_provider_test.cpp\nindex 8b8e7cba..4b087fcb 100644\n--- a/test/gstreamer/gstreamer_device_provider_test.cpp\n+++ b/test/gstreamer/gstreamer_device_provider_test.cpp\n@@ -52,17 +52,12 @@ protected:\n \t\tfor (l = devices; l != NULL; l = g_list_next(l)) {\n \t\t\tGstDevice *device = GST_DEVICE(l->data);\n \t\t\tg_autofree gchar *gst_name;\n-\t\t\tbool matched = false;\n \n \t\t\tg_autoptr(GstElement) element = gst_device_create_element(device, NULL);\n \t\t\tg_object_get(element, \"camera-name\", &gst_name, NULL);\n \n-\t\t\tfor (auto name : cameraNames) {\n-\t\t\t\tif (strcmp(name.c_str(), gst_name) == 0) {\n-\t\t\t\t\tmatched = true;\n-\t\t\t\t\tbreak;\n-\t\t\t\t}\n-\t\t\t}\n+\t\t\tbool matched =\n+\t\t\t\tstd::find(cameraNames.begin(), cameraNames.end(), gst_name) != cameraNames.end();\n \n \t\t\tif (!matched)\n \t\t\t\treturn TestFail;\n", "prefixes": [ "v1" ] }