From patchwork Tue Apr 18 16:26:04 2023 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: 18538 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 B5404BE173 for ; Tue, 18 Apr 2023 16:26:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0DFF5627B8; Tue, 18 Apr 2023 18:26:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1681835182; bh=DAsR0m+SB229Fq2OEKmIOPcHdo/ishfT1b+qAfBNldQ=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=g4jf+XjjWzuCrIUGEP3al++0GDgYTf2qzgC/23yOwT2NVb886WIHwf0DqGmIMgHOS JLmZzbXIRhcm7xGFZRhGBCREWwIAnCEnQtrAEhlL43ikmq4HpdIC55z1ymoyHgtscV zkEteisldLmrmYKTyMHQ5mICiQA/elyOZ6V9F0piVDOZjSdsK3MJvhN0yxWO279m0O mNEniZq08sdP8jLvk7LV8LE4DX/dGXYx2lzQQ+RCRxS2LxWis+Tt/w/ODqNyZ3T+9T BSoSlYzON7DfqMBNAQfQqlMTcdqbvj1SSSRUG14dTUiaEn5KwXY+gt4FKTJacH2v85 A4e70p4VhxGKQ== Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 16DA7603A2 for ; Tue, 18 Apr 2023 18:26:20 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="G4X23FUs"; dkim-atps=neutral Date: Tue, 18 Apr 2023 16:26:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1681835179; x=1682094379; bh=DAsR0m+SB229Fq2OEKmIOPcHdo/ishfT1b+qAfBNldQ=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=G4X23FUsxFYiVoJoP+tpCzDYSio/tXghEk+joKMvDbEyWaYLY1gIwBt4cyBuU+2Ne kVgSwUSlxsEH40+TdMDNLBD96w68g3LwY2skFgy7HKd4gCve3+6+HpSw9+e27hdc39 LSsJoygLEbRa9+6CJP5vEfKxpIoodBDZQuo75TqHDUlizshaHDicFkJiDUw2BG8/Vc 5K550XWXfO9txMaUg6NSnT/UJozjziNo7/+OHEQkUNyKA6yeBAHXkSzTO7nnKNARV5 1sE8tMk4VBn7xAZ8p6j34uybEsNQ7WdLil2mbJAm3ITxwG0nkwkr3uuoSLsB40fsOc 9IV7TdtJeOEOg== To: libcamera-devel@lists.libcamera.org Message-ID: <20230418162603.449433-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] libcamera: device_enumerator_udev: Use std::string_view 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: , X-Patchwork-Original-From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze_via_libcamera-devel?= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" In `udevNotify()`, constructing an std::string from the device's associated action is unnecessary as it is only compared against static strings, and for that purpose an std::string_view works just as well, while being cheaper to construct. In the same vein, an std::string_view can be used to store the device's devnode initially, and the string construction can be deferred until it is needed. Furthermore, previously `udev_device_get_devnode()` was called twice. The extra call is now removed. Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/libcamera/device_enumerator_udev.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) -- 2.40.0 diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp index a63cd360..0abc1248 100644 --- a/src/libcamera/device_enumerator_udev.cpp +++ b/src/libcamera/device_enumerator_udev.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -331,18 +332,18 @@ int DeviceEnumeratorUdev::addV4L2Device(dev_t devnum) void DeviceEnumeratorUdev::udevNotify() { struct udev_device *dev = udev_monitor_receive_device(monitor_); - std::string action(udev_device_get_action(dev)); - std::string deviceNode(udev_device_get_devnode(dev)); + std::string_view action(udev_device_get_action(dev)); + std::string_view deviceNode(udev_device_get_devnode(dev)); LOG(DeviceEnumerator, Debug) - << action << " device " << udev_device_get_devnode(dev); + << action << " device " << deviceNode; if (action == "add") { addUdevDevice(dev); } else if (action == "remove") { const char *subsystem = udev_device_get_subsystem(dev); if (subsystem && !strcmp(subsystem, "media")) - removeDevice(deviceNode); + removeDevice(std::string(deviceNode)); } udev_device_unref(dev);