[libcamera-devel] [PATCH 2/3] libcamera: use const reference for range loops
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Tue Aug 16 05:48:59 CEST 2022
Hi Christian,
Thank you for the patch.
On Sun, Aug 14, 2022 at 11:52:40AM +0200, Christian Rauch via libcamera-devel wrote:
> Signed-off-by: Christian Rauch <Rauch.Christian at gmx.de>
Ah, that's better, the SoB line is there, but the commit message is
still missing :-)
> ---
> src/libcamera/camera_manager.cpp | 2 +-
> src/libcamera/device_enumerator.cpp | 2 +-
> src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 5 +----
> src/libcamera/pipeline/vimc/vimc.cpp | 2 +-
> src/libcamera/pipeline_handler.cpp | 2 +-
> 5 files changed, 5 insertions(+), 8 deletions(-)
>
> diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp
> index 70d73822..7ff4bc6f 100644
> --- a/src/libcamera/camera_manager.cpp
> +++ b/src/libcamera/camera_manager.cpp
> @@ -189,7 +189,7 @@ void CameraManager::Private::addCamera(std::shared_ptr<Camera> camera,
> {
> MutexLocker locker(mutex_);
>
> - for (std::shared_ptr<Camera> c : cameras_) {
> + for (const std::shared_ptr<Camera> &c : cameras_) {
> if (c->id() == camera->id()) {
> LOG(Camera, Fatal)
> << "Trying to register a camera with a duplicated ID '"
> diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp
> index d1258050..f2e055de 100644
> --- a/src/libcamera/device_enumerator.cpp
> +++ b/src/libcamera/device_enumerator.cpp
> @@ -161,7 +161,7 @@ std::unique_ptr<DeviceEnumerator> DeviceEnumerator::create()
>
> DeviceEnumerator::~DeviceEnumerator()
> {
> - for (std::shared_ptr<MediaDevice> media : devices_) {
> + for (const std::shared_ptr<MediaDevice> &media : devices_) {
> if (media->busy())
> LOG(DeviceEnumerator, Error)
> << "Removing media device " << media->deviceNode()
> diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> index fbe02cdc..0306f56c 100644
> --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> @@ -340,10 +340,7 @@ int PipelineHandlerUVC::processControls(UVCCameraData *data, Request *request)
> {
> ControlList controls(data->video_->controls());
>
> - for (auto it : request->controls()) {
> - unsigned int id = it.first;
> - ControlValue &value = it.second;
> -
> + for (const auto &[id, value] : request->controls()) {
Technically speaking this does more than using a const reference. I
don't mind bundling it in this patch, but it should then be mentioned in
the commit message.
> processControl(&controls, id, value);
> }
No need for curly braces anymore.
>
> diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp
> index 153cf849..d2f2e460 100644
> --- a/src/libcamera/pipeline/vimc/vimc.cpp
> +++ b/src/libcamera/pipeline/vimc/vimc.cpp
> @@ -378,7 +378,7 @@ int PipelineHandlerVimc::processControls(VimcCameraData *data, Request *request)
> {
> ControlList controls(data->sensor_->controls());
>
> - for (auto it : request->controls()) {
> + for (const auto &it : request->controls()) {
> unsigned int id = it.first;
> unsigned int offset;
> uint32_t cid;
> diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp
> index 7d2d00ef..e5cb751c 100644
> --- a/src/libcamera/pipeline_handler.cpp
> +++ b/src/libcamera/pipeline_handler.cpp
> @@ -616,7 +616,7 @@ void PipelineHandler::disconnect()
> */
> std::vector<std::weak_ptr<Camera>> cameras{ std::move(cameras_) };
>
> - for (std::weak_ptr<Camera> ptr : cameras) {
> + for (const std::weak_ptr<Camera> &ptr : cameras) {
> std::shared_ptr<Camera> camera = ptr.lock();
> if (!camera)
> continue;
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list