[libcamera-devel] libcamera: media_device: Return string references to avoid copies
diff mbox series

Message ID 20220526133052.18791-1-laurent.pinchart@ideasonboard.com
State Accepted
Commit 7d1f03e5baaa783eeb0587bbbf319eacc1383ab7
Headers show
Series
  • [libcamera-devel] libcamera: media_device: Return string references to avoid copies
Related show

Commit Message

Laurent Pinchart May 26, 2022, 1:30 p.m. UTC
The MediaDevice::driver(), deviceNode() and model() functions return a
const std::string, copying the string stored internally in the class.
Return references instead to avoid copies.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 include/libcamera/internal/media_device.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)


base-commit: f8e4649680303ce9b7dace5ad1344fcb450013ac

Comments

Kieran Bingham May 26, 2022, 2:02 p.m. UTC | #1
Quoting Laurent Pinchart via libcamera-devel (2022-05-26 14:30:52)
> The MediaDevice::driver(), deviceNode() and model() functions return a
> const std::string, copying the string stored internally in the class.
> Return references instead to avoid copies.
> 

Seems quite reasonable.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  include/libcamera/internal/media_device.h | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h
> index 6e2a63f38229..eb8cfde48e20 100644
> --- a/include/libcamera/internal/media_device.h
> +++ b/include/libcamera/internal/media_device.h
> @@ -38,9 +38,9 @@ public:
>         int populate();
>         bool isValid() const { return valid_; }
>  
> -       const std::string driver() const { return driver_; }
> -       const std::string deviceNode() const { return deviceNode_; }
> -       const std::string model() const { return model_; }
> +       const std::string &driver() const { return driver_; }
> +       const std::string &deviceNode() const { return deviceNode_; }
> +       const std::string &model() const { return model_; }
>         unsigned int version() const { return version_; }
>         unsigned int hwRevision() const { return hwRevision_; }
>  
> 
> base-commit: f8e4649680303ce9b7dace5ad1344fcb450013ac
> -- 
> Regards,
> 
> Laurent Pinchart
>
Nicolas Dufresne via libcamera-devel May 27, 2022, 2:43 a.m. UTC | #2
Hi Laurent,

On Thu, May 26, 2022 at 04:30:52PM +0300, Laurent Pinchart via libcamera-devel wrote:
> The MediaDevice::driver(), deviceNode() and model() functions return a
> const std::string, copying the string stored internally in the class.
> Return references instead to avoid copies.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
>  include/libcamera/internal/media_device.h | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h
> index 6e2a63f38229..eb8cfde48e20 100644
> --- a/include/libcamera/internal/media_device.h
> +++ b/include/libcamera/internal/media_device.h
> @@ -38,9 +38,9 @@ public:
>  	int populate();
>  	bool isValid() const { return valid_; }
>  
> -	const std::string driver() const { return driver_; }
> -	const std::string deviceNode() const { return deviceNode_; }
> -	const std::string model() const { return model_; }
> +	const std::string &driver() const { return driver_; }
> +	const std::string &deviceNode() const { return deviceNode_; }
> +	const std::string &model() const { return model_; }
>  	unsigned int version() const { return version_; }
>  	unsigned int hwRevision() const { return hwRevision_; }
>  
> 
> base-commit: f8e4649680303ce9b7dace5ad1344fcb450013ac

Patch
diff mbox series

diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h
index 6e2a63f38229..eb8cfde48e20 100644
--- a/include/libcamera/internal/media_device.h
+++ b/include/libcamera/internal/media_device.h
@@ -38,9 +38,9 @@  public:
 	int populate();
 	bool isValid() const { return valid_; }
 
-	const std::string driver() const { return driver_; }
-	const std::string deviceNode() const { return deviceNode_; }
-	const std::string model() const { return model_; }
+	const std::string &driver() const { return driver_; }
+	const std::string &deviceNode() const { return deviceNode_; }
+	const std::string &model() const { return model_; }
 	unsigned int version() const { return version_; }
 	unsigned int hwRevision() const { return hwRevision_; }