[libcamera-devel,5/8] android: CameraDevice: Return const shared_ptr& by camera()
diff mbox series

Message ID 20210323014226.3211412-6-hiroh@chromium.org
State Superseded
Headers show
Series
  • Improve pointer types in android HAL adaptation layer
Related show

Commit Message

Hirokazu Honda March 23, 2021, 1:42 a.m. UTC
CameraDevice::camera() originally returns shared_ptr. It is
mandatory to make a copy by calling camera() in this way. There
is no need of copying if a caller needs the reference of the
camera like const shared_ptr<Camera> cam = camera(). That is, it
is a caller that copying is required. This changes the return
type of camera() to const shared_ptr&, so that we are able to
reduce one redundant copy in the above case.

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>

---
 src/android/camera_device.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--
2.31.0.rc2.261.g7f71774620-goog

Comments

Laurent Pinchart March 23, 2021, 2:04 a.m. UTC | #1
Hi Hiro,

Thank you for the patch.

On Tue, Mar 23, 2021 at 10:42:23AM +0900, Hirokazu Honda wrote:
> CameraDevice::camera() originally returns shared_ptr. It is
> mandatory to make a copy by calling camera() in this way. There
> is no need of copying if a caller needs the reference of the
> camera like const shared_ptr<Camera> cam = camera(). That is, it

Did you mean '&cam' there ?

> is a caller that copying is required. This changes the return
> type of camera() to const shared_ptr&, so that we are able to
> reduce one redundant copy in the above case.
> 
> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  src/android/camera_device.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/android/camera_device.h b/src/android/camera_device.h
> index 555b33e7..14e26b4d 100644
> --- a/src/android/camera_device.h
> +++ b/src/android/camera_device.h
> @@ -43,7 +43,7 @@ public:
> 
>  	unsigned int id() const { return id_; }
>  	camera3_device_t *camera3Device() { return &camera3Device_; }
> -	std::shared_ptr<libcamera::Camera> camera() const { return camera_; }
> +	const std::shared_ptr<libcamera::Camera> &camera() const { return camera_; }
>  	libcamera::CameraConfiguration *cameraConfiguration() const
>  	{
>  		return config_.get();
Hirokazu Honda March 23, 2021, 2:34 a.m. UTC | #2
Hi Laurent, thanks for reviewing.

On Tue, Mar 23, 2021 at 11:05 AM Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
>
> Hi Hiro,
>
> Thank you for the patch.
>
> On Tue, Mar 23, 2021 at 10:42:23AM +0900, Hirokazu Honda wrote:
> > CameraDevice::camera() originally returns shared_ptr. It is
> > mandatory to make a copy by calling camera() in this way. There
> > is no need of copying if a caller needs the reference of the
> > camera like const shared_ptr<Camera> cam = camera(). That is, it
>
> Did you mean '&cam' there ?
>

Yes, sorry for my mistake.

> > is a caller that copying is required. This changes the return
> > type of camera() to const shared_ptr&, so that we are able to
> > reduce one redundant copy in the above case.
> >
> > Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>
> > ---
> >  src/android/camera_device.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/src/android/camera_device.h b/src/android/camera_device.h
> > index 555b33e7..14e26b4d 100644
> > --- a/src/android/camera_device.h
> > +++ b/src/android/camera_device.h
> > @@ -43,7 +43,7 @@ public:
> >
> >       unsigned int id() const { return id_; }
> >       camera3_device_t *camera3Device() { return &camera3Device_; }
> > -     std::shared_ptr<libcamera::Camera> camera() const { return camera_; }
> > +     const std::shared_ptr<libcamera::Camera> &camera() const { return camera_; }
> >       libcamera::CameraConfiguration *cameraConfiguration() const
> >       {
> >               return config_.get();
>
> --
> Regards,
>
> Laurent Pinchart

Patch
diff mbox series

diff --git a/src/android/camera_device.h b/src/android/camera_device.h
index 555b33e7..14e26b4d 100644
--- a/src/android/camera_device.h
+++ b/src/android/camera_device.h
@@ -43,7 +43,7 @@  public:

 	unsigned int id() const { return id_; }
 	camera3_device_t *camera3Device() { return &camera3Device_; }
-	std::shared_ptr<libcamera::Camera> camera() const { return camera_; }
+	const std::shared_ptr<libcamera::Camera> &camera() const { return camera_; }
 	libcamera::CameraConfiguration *cameraConfiguration() const
 	{
 		return config_.get();