[{"id":38189,"web_url":"https://patchwork.libcamera.org/comment/38189/","msgid":"<177090052666.3376561.9665687379376145993@ping.linuxembedded.co.uk>","date":"2026-02-12T12:48:46","subject":"Re: [PATCH] libcamera: Replace iterators with structured bindings","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Laurent Pinchart (2026-02-12 12:35:55)\n> Use structured bindings when iterating over a map in range-based for\n> loops. This improves readability.\n\nI think you know my dislike for .first/.second readability\nso this is a very easy:\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/libcamera/pipeline/ipu3/ipu3.cpp | 11 +++--------\n>  src/libcamera/pipeline/vimc/vimc.cpp |  3 +--\n>  src/libcamera/v4l2_videodevice.cpp   |  6 ++----\n>  3 files changed, 6 insertions(+), 14 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index 0190f677e679..d1d4d85ebe76 100644\n> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> @@ -791,8 +791,7 @@ void IPU3CameraData::cancelPendingRequests()\n>         while (!pendingRequests_.empty()) {\n>                 Request *request = pendingRequests_.front();\n>  \n> -               for (auto it : request->buffers()) {\n> -                       FrameBuffer *buffer = it.second;\n> +               for (auto [stream, buffer] : request->buffers()) {\n>                         buffer->_d()->cancel();\n>                         pipe()->completeBuffer(request, buffer);\n>                 }\n> @@ -1225,10 +1224,7 @@ void IPU3CameraData::paramsComputed(unsigned int id)\n>                 return;\n>  \n>         /* Queue all buffers from the request aimed for the ImgU. */\n> -       for (auto it : info->request->buffers()) {\n> -               const Stream *stream = it.first;\n> -               FrameBuffer *outbuffer = it.second;\n> -\n> +       for (auto [stream, outbuffer] : info->request->buffers()) {\n>                 if (stream == &outStream_)\n>                         imgu_->output_->queueBuffer(outbuffer);\n>                 else if (stream == &vfStream_)\n> @@ -1304,8 +1300,7 @@ void IPU3CameraData::cio2BufferReady(FrameBuffer *buffer)\n>  \n>         /* If the buffer is cancelled force a complete of the whole request. */\n>         if (buffer->metadata().status == FrameMetadata::FrameCancelled) {\n> -               for (auto it : request->buffers()) {\n> -                       FrameBuffer *b = it.second;\n> +               for (auto [stream, b] : request->buffers()) {\n>                         b->_d()->cancel();\n>                         pipe()->completeBuffer(request, b);\n>                 }\n> diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp\n> index 4a03c149a617..025e7dbdd26f 100644\n> --- a/src/libcamera/pipeline/vimc/vimc.cpp\n> +++ b/src/libcamera/pipeline/vimc/vimc.cpp\n> @@ -607,8 +607,7 @@ void VimcCameraData::imageBufferReady(FrameBuffer *buffer)\n>  \n>         /* If the buffer is cancelled force a complete of the whole request. */\n>         if (buffer->metadata().status == FrameMetadata::FrameCancelled) {\n> -               for (auto it : request->buffers()) {\n> -                       FrameBuffer *b = it.second;\n> +               for (auto [stream, b] : request->buffers()) {\n>                         b->_d()->cancel();\n>                         pipe->completeBuffer(request, b);\n>                 }\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 25b61d049a0e..02c50886a084 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -2042,10 +2042,8 @@ int V4L2VideoDevice::streamOff()\n>         state_ = State::Stopping;\n>  \n>         /* Send back all queued buffers. */\n> -       for (auto it : queuedBuffers_) {\n> -               FrameBuffer *buffer = it.second;\n> -\n> -               cache_->put(it.first);\n> +       for (auto [id, buffer] : queuedBuffers_) {\n> +               cache_->put(id);\n>                 buffer->_d()->cancel();\n>                 bufferReady.emit(buffer);\n>         }\n> \n> base-commit: 1dcf9957a47fb54fce4fbae9daec0b587e52562e\n> -- \n> Regards,\n> \n> Laurent Pinchart\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 522DABD78E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 12 Feb 2026 12:48:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 343F5621D0;\n\tThu, 12 Feb 2026 13:48:51 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1242661FBF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 12 Feb 2026 13:48:50 +0100 (CET)","from monstersaurus.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E133511EB;\n\tThu, 12 Feb 2026 13:48:01 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"jPVzIh6o\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1770900482;\n\tbh=7PdKzRhA3VY8uflcJmygF+MV6l4wobPW7cjkMdgy4C0=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=jPVzIh6oJWuE3W3jH8lzP//vnP7s4bE6vHsL53xOECiedkBbQSJyZraq9tXTbc1Hd\n\tEUA5aV4FrqVVSOABEPz6g0VfclCCoSmHtkxVcgm1SHAvHrYUbdJNDuvDQHhiCPS5vh\n\tuNU3KCqV8/xa8xJZuTbx2bNB8YKpaSfencTBIc5g=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20260212123555.2686756-1-laurent.pinchart@ideasonboard.com>","References":"<20260212123555.2686756-1-laurent.pinchart@ideasonboard.com>","Subject":"Re: [PATCH] libcamera: Replace iterators with structured bindings","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Thu, 12 Feb 2026 12:48:46 +0000","Message-ID":"<177090052666.3376561.9665687379376145993@ping.linuxembedded.co.uk>","User-Agent":"alot/0.9.1","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":38190,"web_url":"https://patchwork.libcamera.org/comment/38190/","msgid":"<96556725-307e-4eba-918e-d44c908eb624@ideasonboard.com>","date":"2026-02-12T12:49:26","subject":"Re: [PATCH] libcamera: Replace iterators with structured bindings","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"2026. 02. 12. 13:35 keltezéssel, Laurent Pinchart írta:\n> Use structured bindings when iterating over a map in range-based for\n> loops. This improves readability.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>   src/libcamera/pipeline/ipu3/ipu3.cpp | 11 +++--------\n>   src/libcamera/pipeline/vimc/vimc.cpp |  3 +--\n>   src/libcamera/v4l2_videodevice.cpp   |  6 ++----\n>   3 files changed, 6 insertions(+), 14 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index 0190f677e679..d1d4d85ebe76 100644\n> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> @@ -791,8 +791,7 @@ void IPU3CameraData::cancelPendingRequests()\n>   \twhile (!pendingRequests_.empty()) {\n>   \t\tRequest *request = pendingRequests_.front();\n>   \n> -\t\tfor (auto it : request->buffers()) {\n> -\t\t\tFrameBuffer *buffer = it.second;\n> +\t\tfor (auto [stream, buffer] : request->buffers()) {\n\nI think it might be better to default to `const auto&` as a rule of thumb to avoid copies.\n\nAnd I can also see a couple other hits for `for (const auto &it` and `for (auto const &it`,\nthose might also be worth converting.\n\n\nReviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n\n\n>   \t\t\tbuffer->_d()->cancel();\n>   \t\t\tpipe()->completeBuffer(request, buffer);\n>   \t\t}\n> @@ -1225,10 +1224,7 @@ void IPU3CameraData::paramsComputed(unsigned int id)\n>   \t\treturn;\n>   \n>   \t/* Queue all buffers from the request aimed for the ImgU. */\n> -\tfor (auto it : info->request->buffers()) {\n> -\t\tconst Stream *stream = it.first;\n> -\t\tFrameBuffer *outbuffer = it.second;\n> -\n> +\tfor (auto [stream, outbuffer] : info->request->buffers()) {\n>   \t\tif (stream == &outStream_)\n>   \t\t\timgu_->output_->queueBuffer(outbuffer);\n>   \t\telse if (stream == &vfStream_)\n> @@ -1304,8 +1300,7 @@ void IPU3CameraData::cio2BufferReady(FrameBuffer *buffer)\n>   \n>   \t/* If the buffer is cancelled force a complete of the whole request. */\n>   \tif (buffer->metadata().status == FrameMetadata::FrameCancelled) {\n> -\t\tfor (auto it : request->buffers()) {\n> -\t\t\tFrameBuffer *b = it.second;\n> +\t\tfor (auto [stream, b] : request->buffers()) {\n>   \t\t\tb->_d()->cancel();\n>   \t\t\tpipe()->completeBuffer(request, b);\n>   \t\t}\n> diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp\n> index 4a03c149a617..025e7dbdd26f 100644\n> --- a/src/libcamera/pipeline/vimc/vimc.cpp\n> +++ b/src/libcamera/pipeline/vimc/vimc.cpp\n> @@ -607,8 +607,7 @@ void VimcCameraData::imageBufferReady(FrameBuffer *buffer)\n>   \n>   \t/* If the buffer is cancelled force a complete of the whole request. */\n>   \tif (buffer->metadata().status == FrameMetadata::FrameCancelled) {\n> -\t\tfor (auto it : request->buffers()) {\n> -\t\t\tFrameBuffer *b = it.second;\n> +\t\tfor (auto [stream, b] : request->buffers()) {\n>   \t\t\tb->_d()->cancel();\n>   \t\t\tpipe->completeBuffer(request, b);\n>   \t\t}\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 25b61d049a0e..02c50886a084 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -2042,10 +2042,8 @@ int V4L2VideoDevice::streamOff()\n>   \tstate_ = State::Stopping;\n>   \n>   \t/* Send back all queued buffers. */\n> -\tfor (auto it : queuedBuffers_) {\n> -\t\tFrameBuffer *buffer = it.second;\n> -\n> -\t\tcache_->put(it.first);\n> +\tfor (auto [id, buffer] : queuedBuffers_) {\n> +\t\tcache_->put(id);\n>   \t\tbuffer->_d()->cancel();\n>   \t\tbufferReady.emit(buffer);\n>   \t}\n> \n> base-commit: 1dcf9957a47fb54fce4fbae9daec0b587e52562e","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 945F3BDE6B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 12 Feb 2026 12:49:30 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 42103621CA;\n\tThu, 12 Feb 2026 13:49:30 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4ADDB62181\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 12 Feb 2026 13:49:29 +0100 (CET)","from [192.168.33.66] (185.221.141.206.nat.pool.zt.hu\n\t[185.221.141.206])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 65AE8E70;\n\tThu, 12 Feb 2026 13:48:41 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Pjeg9LWd\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1770900521;\n\tbh=0YNFxuHJOdgNNe0ieKHmaToUBtoPZv3RGSiwpJmG+Vk=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=Pjeg9LWdNztRt/P87EcvEzQ8EcrPZ0JU88oTkdZ65p+STnsd8qvYG5ONzNKL/sH/T\n\tSizUWZBKrcR+3pd11c6qET7ijTcqxfzLBYrcfqdX8fTqvhKsuKOWpKcGtqv6km0rbX\n\tRQvecRpz7XtLO0MoJs3N4tFwXhKP9+rWgWb0Wsvs=","Message-ID":"<96556725-307e-4eba-918e-d44c908eb624@ideasonboard.com>","Date":"Thu, 12 Feb 2026 13:49:26 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH] libcamera: Replace iterators with structured bindings","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20260212123555.2686756-1-laurent.pinchart@ideasonboard.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<20260212123555.2686756-1-laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]