Patch Detail
Show a patch.
GET /api/1.1/patches/11738/?format=api
{ "id": 11738, "url": "https://patchwork.libcamera.org/api/1.1/patches/11738/?format=api", "web_url": "https://patchwork.libcamera.org/patch/11738/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/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": "<20210328025741.30246-1-laurent.pinchart@ideasonboard.com>", "date": "2021-03-28T02:57:41", "name": "[libcamera-devel,v2] libcamera: pipeline: uvcvideo: Avoid reference to temporary object", "commit_ref": "299e8ef563a83ce6e9624bb21e11ecb2ad5a228f", "pull_url": null, "state": "accepted", "archived": false, "hash": "3cbd7e7b9633cf45149783117b752ed962be04de", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/11738/mbox/", "series": [ { "id": 1847, "url": "https://patchwork.libcamera.org/api/1.1/series/1847/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1847", "date": "2021-03-28T02:57:41", "name": "[libcamera-devel,v2] libcamera: pipeline: uvcvideo: Avoid reference to temporary object", "version": 2, "mbox": "https://patchwork.libcamera.org/series/1847/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/11738/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/11738/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 CCA6DC32ED\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 28 Mar 2021 02:58:32 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C53DE68781;\n\tSun, 28 Mar 2021 04:58:31 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B5A886877C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 28 Mar 2021 04:58:29 +0200 (CEST)", "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 11F12332;\n\tSun, 28 Mar 2021 04:58:28 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"MniKswyT\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1616900309;\n\tbh=BwCg4h9N9fJysbMT1Yjbazbp7zTImD9mkWJSjCKzCmg=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=MniKswyT+aUtPgeMFeLqW6cRMFsPRN4W1XtVDA6pqI0QTSSx5koEuzSfEybjs6Qbp\n\tZdQar1r5nBIRCg9uq85YoLKoFeT7WN4PrwnRYPwaYGAFHfV44rDrq4RBe3VOIb+85W\n\ttKn4HEzjlFelrImVbeymBsgpVhITveSVH1MdYRsE=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Sun, 28 Mar 2021 05:57:41 +0300", "Message-Id": "<20210328025741.30246-1-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.28.1", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH v2] libcamera: pipeline: uvcvideo: Avoid\n\treference to temporary object", "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>", "Content-Type": "text/plain; charset=\"us-ascii\"", "Content-Transfer-Encoding": "7bit", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "From: Khem Raj <raj.khem@gmail.com>\n\nA range-based for loop whose range expression is an array of char\npointers and range variable declaration is a const reference to a\nstd::string creates a temporary string from the char pointer and binds\nthe range variable reference to it. This creates a const reference to a\ntemporary, which is valid in C++, and extends the lifetime of the\ntemporary to the lifetime of the reference.\n\nHowever, lifetime extension in range-based for loops is considered as a\nsign of a potential issue, as a temporary is created for every\niteration, which can be costly, and the usage of a reference in the\nrange declaration doesn't make it obvious that the code isn't simply\nbinding a reference to an existing object. gcc 11, with the\n-Wrange-loop-construct option, flags this:\n\nuvcvideo.cpp:432:33: error: loop variable 'name' of type 'const string&' {aka 'const std::__cxx11::basic_string<cha\nr>&'} binds to a temporary constructed from type 'const char* const' [-Werror=range-loop-construct]\n| 432 | for (const std::string &name : { \"idVendor\", \"idProduct\" }) {\n| | ^~~~\n\nTo please the compiler, make the range variable a const char *. This may\nbring a tiny performance improvement, as the name is only used once, in\na location where the compiler can use\n\n\toperator+(const std::string &, const char *)\n\ninstead of\n\n\toperator+(const std::string &, const std::string &)\n\nSigned-off-by: Khem Raj <raj.khem@gmail.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nUse a const char * type instead of auto, and update the commit message\naccordingly.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)", "diff": "diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\nindex 031f96e28449..b6c6ade5ebaf 100644\n--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n@@ -429,7 +429,7 @@ std::string PipelineHandlerUVC::generateId(const UVCCameraData *data)\n \n \t/* Creata a device ID from the USB devices vendor and product ID. */\n \tstd::string deviceId;\n-\tfor (const std::string &name : { \"idVendor\", \"idProduct\" }) {\n+\tfor (const char *name : { \"idVendor\", \"idProduct\" }) {\n \t\tstd::ifstream file(path + \"/../\" + name);\n \n \t\tif (!file.is_open())\n", "prefixes": [ "libcamera-devel", "v2" ] }