[libcamera-devel] [PATCH] libcamera: device_enumerator_udev: Use std::string_view

Laurent Pinchart laurent.pinchart at ideasonboard.com
Tue Apr 18 18:14:49 CEST 2023


Hi Barnabás,

Thank you for the patch.

On Tue, Apr 18, 2023 at 04:03:03PM +0000, Barnabás Pőcze via libcamera-devel wrote:
> In `udevNotify()`, use `std::string_view` and defer the necessary
> `std::string` construction to the last possible point.

The commit message should explain why this is a good idea.

> Signed-off-by: Barnabás Pőcze <pobrn at protonmail.com>
> ---
>  src/libcamera/device_enumerator_udev.cpp | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> 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 <list>
>  #include <map>
>  #include <string.h>
> +#include <string_view>
>  #include <sys/ioctl.h>
>  #include <sys/sysmacros.h>
>  #include <unistd.h>
> @@ -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);

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list