[{"id":26894,"web_url":"https://patchwork.libcamera.org/comment/26894/","msgid":"<20230418161449.GJ30837@pendragon.ideasonboard.com>","date":"2023-04-18T16:14:49","subject":"Re: [libcamera-devel] [PATCH] libcamera: device_enumerator_udev:\n\tUse std::string_view","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Barnabás,\n\nThank you for the patch.\n\nOn Tue, Apr 18, 2023 at 04:03:03PM +0000, Barnabás Pőcze via libcamera-devel wrote:\n> In `udevNotify()`, use `std::string_view` and defer the necessary\n> `std::string` construction to the last possible point.\n\nThe commit message should explain why this is a good idea.\n\n> Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n> ---\n>  src/libcamera/device_enumerator_udev.cpp | 9 +++++----\n>  1 file changed, 5 insertions(+), 4 deletions(-)\n> \n> diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp\n> index a63cd360..0abc1248 100644\n> --- a/src/libcamera/device_enumerator_udev.cpp\n> +++ b/src/libcamera/device_enumerator_udev.cpp\n> @@ -13,6 +13,7 @@\n>  #include <list>\n>  #include <map>\n>  #include <string.h>\n> +#include <string_view>\n>  #include <sys/ioctl.h>\n>  #include <sys/sysmacros.h>\n>  #include <unistd.h>\n> @@ -331,18 +332,18 @@ int DeviceEnumeratorUdev::addV4L2Device(dev_t devnum)\n>  void DeviceEnumeratorUdev::udevNotify()\n>  {\n>  \tstruct udev_device *dev = udev_monitor_receive_device(monitor_);\n> -\tstd::string action(udev_device_get_action(dev));\n> -\tstd::string deviceNode(udev_device_get_devnode(dev));\n> +\tstd::string_view action(udev_device_get_action(dev));\n> +\tstd::string_view deviceNode(udev_device_get_devnode(dev));\n> \n>  \tLOG(DeviceEnumerator, Debug)\n> -\t\t<< action << \" device \" << udev_device_get_devnode(dev);\n> +\t\t<< action << \" device \" << deviceNode;\n> \n>  \tif (action == \"add\") {\n>  \t\taddUdevDevice(dev);\n>  \t} else if (action == \"remove\") {\n>  \t\tconst char *subsystem = udev_device_get_subsystem(dev);\n>  \t\tif (subsystem && !strcmp(subsystem, \"media\"))\n> -\t\t\tremoveDevice(deviceNode);\n> +\t\t\tremoveDevice(std::string(deviceNode));\n>  \t}\n> \n>  \tudev_device_unref(dev);","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 4CA5CBD1F1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 18 Apr 2023 16:14:40 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C42C2627B8;\n\tTue, 18 Apr 2023 18:14:39 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 18039603A2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 18 Apr 2023 18:14:38 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(133-32-181-51.west.xps.vectant.ne.jp [133.32.181.51])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E92F5DE5;\n\tTue, 18 Apr 2023 18:14:30 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1681834479;\n\tbh=z2sqboISCKC/NN9hZoHsj8ML7qxZkDHXaC0T583EhSY=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=JO3a4s8MBEyszuGHLic2yOM/3NJfzqSEjEOQVaiOu2eECNOBthDrwDgjGNhDmbs+Q\n\t1cuG3yH1l4pPi8k19Nqop7U44Wt+4sTpJ4yhNJIuxiVaLJi0GCJoUB6Pg7HbPtusbu\n\tHE4n+xDUZe/EgK+UkVgJ0k2HEtrYQXAwuTjCU02V99RxgVge0c4bvlBC7/++4rTZ6a\n\t6uP2LZrB55DZrTmmgA5+DeBgsOmX/Y6AwYPIi+doiU87YUHSYJ+Dxb8QsRT1iYaZWW\n\t2M9C7uzd+iWS9o55ruaDStfzdg3E3Wcplo8CVX3ahmr2ksF4vc3fJnmlv6zbtzUpcP\n\tqfEK6N3YGJvbQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1681834471;\n\tbh=z2sqboISCKC/NN9hZoHsj8ML7qxZkDHXaC0T583EhSY=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=YO96A2HwcBnnGudXsHis3g0UVh/dxbpKp6V5Gup1JDmwztNWbbiI4rooH3suC0WsH\n\tn8q/PI8lBgYbD4PtqMdggSBxB4BYVEdgnyWyrrgnbrM4CNC0gj1wBawSaon6zLdJcw\n\t++opvCRzjG6BMf7ueokGU+Xcp5Vf0RkpCEBTHtBQ="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"YO96A2Hw\"; dkim-atps=neutral","Date":"Tue, 18 Apr 2023 19:14:49 +0300","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>","Message-ID":"<20230418161449.GJ30837@pendragon.ideasonboard.com>","References":"<20230418160301.445828-1-pobrn@protonmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20230418160301.445828-1-pobrn@protonmail.com>","Subject":"Re: [libcamera-devel] [PATCH] libcamera: device_enumerator_udev:\n\tUse std::string_view","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>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]