Message ID | 20250812172310.17441-1-laurent.pinchart@ideasonboard.com |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
Quoting Laurent Pinchart (2025-08-12 18:23:10) > The FrameBuffer constructor takes a list of planes as an std::vector. > The caller may stores the planes in a different type of container, > resulting in the needless allocation of a temporary vector. Replace it > with a span. > > Suggested-by: Daniel Rákos <daniel.rakos@rastergrid.com> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- > include/libcamera/framebuffer.h | 2 +- > include/libcamera/internal/framebuffer.h | 3 ++- > src/android/mm/cros_frame_buffer_allocator.cpp | 2 +- > src/android/mm/generic_frame_buffer_allocator.cpp | 2 +- > src/libcamera/framebuffer.cpp | 8 ++++---- > 5 files changed, 9 insertions(+), 8 deletions(-) > > diff --git a/include/libcamera/framebuffer.h b/include/libcamera/framebuffer.h > index e83825b466aa..653c1a96132f 100644 > --- a/include/libcamera/framebuffer.h > +++ b/include/libcamera/framebuffer.h > @@ -58,7 +58,7 @@ public: > unsigned int length; > }; > > - FrameBuffer(const std::vector<Plane> &planes, unsigned int cookie = 0); > + FrameBuffer(Span<const Plane> planes, unsigned int cookie = 0); Public ABI change? Although it's probably API compatible when recompiled anyway. We need some tag to highlight these for the release notes ideally but API/ABI breakage window is open so: Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> > FrameBuffer(std::unique_ptr<Private> d); > virtual ~FrameBuffer() {} > > diff --git a/include/libcamera/internal/framebuffer.h b/include/libcamera/internal/framebuffer.h > index 97b49d42063f..67b090fc307f 100644 > --- a/include/libcamera/internal/framebuffer.h > +++ b/include/libcamera/internal/framebuffer.h > @@ -12,6 +12,7 @@ > #include <utility> > > #include <libcamera/base/class.h> > +#include <libcamera/base/span.h> > > #include <libcamera/fence.h> > #include <libcamera/framebuffer.h> > @@ -23,7 +24,7 @@ class FrameBuffer::Private : public Extensible::Private > LIBCAMERA_DECLARE_PUBLIC(FrameBuffer) > > public: > - Private(const std::vector<Plane> &planes, uint64_t cookie = 0); > + Private(Span<const Plane> planes, uint64_t cookie = 0); > virtual ~Private(); > > void setRequest(Request *request) { request_ = request; } > diff --git a/src/android/mm/cros_frame_buffer_allocator.cpp b/src/android/mm/cros_frame_buffer_allocator.cpp > index 264c0d481272..7ec116e1500d 100644 > --- a/src/android/mm/cros_frame_buffer_allocator.cpp > +++ b/src/android/mm/cros_frame_buffer_allocator.cpp > @@ -29,7 +29,7 @@ class CrosFrameBufferData : public FrameBuffer::Private > > public: > CrosFrameBufferData(cros::ScopedBufferHandle scopedHandle, > - const std::vector<FrameBuffer::Plane> &planes) > + Span<const FrameBuffer::Plane> planes) > : FrameBuffer::Private(planes), scopedHandle_(std::move(scopedHandle)) > { > } > diff --git a/src/android/mm/generic_frame_buffer_allocator.cpp b/src/android/mm/generic_frame_buffer_allocator.cpp > index 79625a9a3c75..25ad6b035e73 100644 > --- a/src/android/mm/generic_frame_buffer_allocator.cpp > +++ b/src/android/mm/generic_frame_buffer_allocator.cpp > @@ -35,7 +35,7 @@ class GenericFrameBufferData : public FrameBuffer::Private > public: > GenericFrameBufferData(struct alloc_device_t *allocDevice, > buffer_handle_t handle, > - const std::vector<FrameBuffer::Plane> &planes) > + Span<const FrameBuffer::Plane> planes) > : FrameBuffer::Private(planes), allocDevice_(allocDevice), > handle_(handle) > { > diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp > index 219db50d6527..cb849b8e40fe 100644 > --- a/src/libcamera/framebuffer.cpp > +++ b/src/libcamera/framebuffer.cpp > @@ -130,9 +130,9 @@ LOG_DEFINE_CATEGORY(Buffer) > * \param[in] planes The frame memory planes > * \param[in] cookie Cookie > */ > -FrameBuffer::Private::Private(const std::vector<Plane> &planes, uint64_t cookie) > - : planes_(planes), cookie_(cookie), request_(nullptr), > - isContiguous_(true) > +FrameBuffer::Private::Private(Span<const Plane> planes, uint64_t cookie) > + : planes_(std::begin(planes), std::end(planes)), cookie_(cookie), > + request_(nullptr), isContiguous_(true) > { > metadata_.planes_.resize(planes_.size()); > } > @@ -315,7 +315,7 @@ ino_t fileDescriptorInode(const SharedFD &fd) > * \param[in] planes The frame memory planes > * \param[in] cookie Cookie > */ > -FrameBuffer::FrameBuffer(const std::vector<Plane> &planes, unsigned int cookie) > +FrameBuffer::FrameBuffer(Span<const Plane> planes, unsigned int cookie) > : FrameBuffer(std::make_unique<Private>(planes, cookie)) > { > } > > base-commit: aa0a91c48ddb38c302390d5c4899cb9e093ddd24 > -- > Regards, > > Laurent Pinchart >
On Tue, Aug 12, 2025 at 06:36:42PM +0100, Kieran Bingham wrote: > Quoting Laurent Pinchart (2025-08-12 18:23:10) > > The FrameBuffer constructor takes a list of planes as an std::vector. > > The caller may stores the planes in a different type of container, > > resulting in the needless allocation of a temporary vector. Replace it > > with a span. > > > > Suggested-by: Daniel Rákos <daniel.rakos@rastergrid.com> > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > > --- > > include/libcamera/framebuffer.h | 2 +- > > include/libcamera/internal/framebuffer.h | 3 ++- > > src/android/mm/cros_frame_buffer_allocator.cpp | 2 +- > > src/android/mm/generic_frame_buffer_allocator.cpp | 2 +- > > src/libcamera/framebuffer.cpp | 8 ++++---- > > 5 files changed, 9 insertions(+), 8 deletions(-) > > > > diff --git a/include/libcamera/framebuffer.h b/include/libcamera/framebuffer.h > > index e83825b466aa..653c1a96132f 100644 > > --- a/include/libcamera/framebuffer.h > > +++ b/include/libcamera/framebuffer.h > > @@ -58,7 +58,7 @@ public: > > unsigned int length; > > }; > > > > - FrameBuffer(const std::vector<Plane> &planes, unsigned int cookie = 0); > > + FrameBuffer(Span<const Plane> planes, unsigned int cookie = 0); > > Public ABI change? Yes. > Although it's probably API compatible when recompiled anyway. It should be, yes. And dynamic linking will fail as the symbol name changes, so you won't get weird crashes. > We need some tag to highlight these for the release notes ideally but > API/ABI breakage window is open so: > > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> > > > FrameBuffer(std::unique_ptr<Private> d); > > virtual ~FrameBuffer() {} > > > > diff --git a/include/libcamera/internal/framebuffer.h b/include/libcamera/internal/framebuffer.h > > index 97b49d42063f..67b090fc307f 100644 > > --- a/include/libcamera/internal/framebuffer.h > > +++ b/include/libcamera/internal/framebuffer.h > > @@ -12,6 +12,7 @@ > > #include <utility> > > > > #include <libcamera/base/class.h> > > +#include <libcamera/base/span.h> > > > > #include <libcamera/fence.h> > > #include <libcamera/framebuffer.h> > > @@ -23,7 +24,7 @@ class FrameBuffer::Private : public Extensible::Private > > LIBCAMERA_DECLARE_PUBLIC(FrameBuffer) > > > > public: > > - Private(const std::vector<Plane> &planes, uint64_t cookie = 0); > > + Private(Span<const Plane> planes, uint64_t cookie = 0); > > virtual ~Private(); > > > > void setRequest(Request *request) { request_ = request; } > > diff --git a/src/android/mm/cros_frame_buffer_allocator.cpp b/src/android/mm/cros_frame_buffer_allocator.cpp > > index 264c0d481272..7ec116e1500d 100644 > > --- a/src/android/mm/cros_frame_buffer_allocator.cpp > > +++ b/src/android/mm/cros_frame_buffer_allocator.cpp > > @@ -29,7 +29,7 @@ class CrosFrameBufferData : public FrameBuffer::Private > > > > public: > > CrosFrameBufferData(cros::ScopedBufferHandle scopedHandle, > > - const std::vector<FrameBuffer::Plane> &planes) > > + Span<const FrameBuffer::Plane> planes) > > : FrameBuffer::Private(planes), scopedHandle_(std::move(scopedHandle)) > > { > > } > > diff --git a/src/android/mm/generic_frame_buffer_allocator.cpp b/src/android/mm/generic_frame_buffer_allocator.cpp > > index 79625a9a3c75..25ad6b035e73 100644 > > --- a/src/android/mm/generic_frame_buffer_allocator.cpp > > +++ b/src/android/mm/generic_frame_buffer_allocator.cpp > > @@ -35,7 +35,7 @@ class GenericFrameBufferData : public FrameBuffer::Private > > public: > > GenericFrameBufferData(struct alloc_device_t *allocDevice, > > buffer_handle_t handle, > > - const std::vector<FrameBuffer::Plane> &planes) > > + Span<const FrameBuffer::Plane> planes) > > : FrameBuffer::Private(planes), allocDevice_(allocDevice), > > handle_(handle) > > { > > diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp > > index 219db50d6527..cb849b8e40fe 100644 > > --- a/src/libcamera/framebuffer.cpp > > +++ b/src/libcamera/framebuffer.cpp > > @@ -130,9 +130,9 @@ LOG_DEFINE_CATEGORY(Buffer) > > * \param[in] planes The frame memory planes > > * \param[in] cookie Cookie > > */ > > -FrameBuffer::Private::Private(const std::vector<Plane> &planes, uint64_t cookie) > > - : planes_(planes), cookie_(cookie), request_(nullptr), > > - isContiguous_(true) > > +FrameBuffer::Private::Private(Span<const Plane> planes, uint64_t cookie) > > + : planes_(std::begin(planes), std::end(planes)), cookie_(cookie), > > + request_(nullptr), isContiguous_(true) > > { > > metadata_.planes_.resize(planes_.size()); > > } > > @@ -315,7 +315,7 @@ ino_t fileDescriptorInode(const SharedFD &fd) > > * \param[in] planes The frame memory planes > > * \param[in] cookie Cookie > > */ > > -FrameBuffer::FrameBuffer(const std::vector<Plane> &planes, unsigned int cookie) > > +FrameBuffer::FrameBuffer(Span<const Plane> planes, unsigned int cookie) > > : FrameBuffer(std::make_unique<Private>(planes, cookie)) > > { > > } > > > > base-commit: aa0a91c48ddb38c302390d5c4899cb9e093ddd24
2025. 08. 12. 19:23 keltezéssel, Laurent Pinchart írta: > The FrameBuffer constructor takes a list of planes as an std::vector. > The caller may stores the planes in a different type of container, > resulting in the needless allocation of a temporary vector. Replace it > with a span. > > Suggested-by: Daniel Rákos <daniel.rakos@rastergrid.com> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- > include/libcamera/framebuffer.h | 2 +- > include/libcamera/internal/framebuffer.h | 3 ++- > src/android/mm/cros_frame_buffer_allocator.cpp | 2 +- > src/android/mm/generic_frame_buffer_allocator.cpp | 2 +- > src/libcamera/framebuffer.cpp | 8 ++++---- > 5 files changed, 9 insertions(+), 8 deletions(-) > > diff --git a/include/libcamera/framebuffer.h b/include/libcamera/framebuffer.h > index e83825b466aa..653c1a96132f 100644 > --- a/include/libcamera/framebuffer.h > +++ b/include/libcamera/framebuffer.h > @@ -58,7 +58,7 @@ public: > unsigned int length; > }; > > - FrameBuffer(const std::vector<Plane> &planes, unsigned int cookie = 0); > + FrameBuffer(Span<const Plane> planes, unsigned int cookie = 0); > FrameBuffer(std::unique_ptr<Private> d); > virtual ~FrameBuffer() {} > > diff --git a/include/libcamera/internal/framebuffer.h b/include/libcamera/internal/framebuffer.h > index 97b49d42063f..67b090fc307f 100644 > --- a/include/libcamera/internal/framebuffer.h > +++ b/include/libcamera/internal/framebuffer.h > @@ -12,6 +12,7 @@ > #include <utility> > > #include <libcamera/base/class.h> > +#include <libcamera/base/span.h> > > #include <libcamera/fence.h> > #include <libcamera/framebuffer.h> > @@ -23,7 +24,7 @@ class FrameBuffer::Private : public Extensible::Private > LIBCAMERA_DECLARE_PUBLIC(FrameBuffer) > > public: > - Private(const std::vector<Plane> &planes, uint64_t cookie = 0); > + Private(Span<const Plane> planes, uint64_t cookie = 0); > virtual ~Private(); > > void setRequest(Request *request) { request_ = request; } > diff --git a/src/android/mm/cros_frame_buffer_allocator.cpp b/src/android/mm/cros_frame_buffer_allocator.cpp > index 264c0d481272..7ec116e1500d 100644 > --- a/src/android/mm/cros_frame_buffer_allocator.cpp > +++ b/src/android/mm/cros_frame_buffer_allocator.cpp > @@ -29,7 +29,7 @@ class CrosFrameBufferData : public FrameBuffer::Private > > public: > CrosFrameBufferData(cros::ScopedBufferHandle scopedHandle, > - const std::vector<FrameBuffer::Plane> &planes) > + Span<const FrameBuffer::Plane> planes) > : FrameBuffer::Private(planes), scopedHandle_(std::move(scopedHandle)) > { > } > diff --git a/src/android/mm/generic_frame_buffer_allocator.cpp b/src/android/mm/generic_frame_buffer_allocator.cpp > index 79625a9a3c75..25ad6b035e73 100644 > --- a/src/android/mm/generic_frame_buffer_allocator.cpp > +++ b/src/android/mm/generic_frame_buffer_allocator.cpp > @@ -35,7 +35,7 @@ class GenericFrameBufferData : public FrameBuffer::Private > public: > GenericFrameBufferData(struct alloc_device_t *allocDevice, > buffer_handle_t handle, > - const std::vector<FrameBuffer::Plane> &planes) > + Span<const FrameBuffer::Plane> planes) > : FrameBuffer::Private(planes), allocDevice_(allocDevice), > handle_(handle) > { > diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp > index 219db50d6527..cb849b8e40fe 100644 > --- a/src/libcamera/framebuffer.cpp > +++ b/src/libcamera/framebuffer.cpp > @@ -130,9 +130,9 @@ LOG_DEFINE_CATEGORY(Buffer) > * \param[in] planes The frame memory planes > * \param[in] cookie Cookie > */ > -FrameBuffer::Private::Private(const std::vector<Plane> &planes, uint64_t cookie) > - : planes_(planes), cookie_(cookie), request_(nullptr), > - isContiguous_(true) > +FrameBuffer::Private::Private(Span<const Plane> planes, uint64_t cookie) > + : planes_(std::begin(planes), std::end(planes)), cookie_(cookie), What was the motivation for using `std::{begin,end}()` instead of `planes.{begin,end}()`? Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> > + request_(nullptr), isContiguous_(true) > { > metadata_.planes_.resize(planes_.size()); > } > @@ -315,7 +315,7 @@ ino_t fileDescriptorInode(const SharedFD &fd) > * \param[in] planes The frame memory planes > * \param[in] cookie Cookie > */ > -FrameBuffer::FrameBuffer(const std::vector<Plane> &planes, unsigned int cookie) > +FrameBuffer::FrameBuffer(Span<const Plane> planes, unsigned int cookie) > : FrameBuffer(std::make_unique<Private>(planes, cookie)) > { > } > > base-commit: aa0a91c48ddb38c302390d5c4899cb9e093ddd24
On Wed, Aug 13, 2025 at 09:00:23AM +0200, Barnabás Pőcze wrote: > 2025. 08. 12. 19:23 keltezéssel, Laurent Pinchart írta: > > The FrameBuffer constructor takes a list of planes as an std::vector. > > The caller may stores the planes in a different type of container, > > resulting in the needless allocation of a temporary vector. Replace it > > with a span. > > > > Suggested-by: Daniel Rákos <daniel.rakos@rastergrid.com> > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > > --- > > include/libcamera/framebuffer.h | 2 +- > > include/libcamera/internal/framebuffer.h | 3 ++- > > src/android/mm/cros_frame_buffer_allocator.cpp | 2 +- > > src/android/mm/generic_frame_buffer_allocator.cpp | 2 +- > > src/libcamera/framebuffer.cpp | 8 ++++---- > > 5 files changed, 9 insertions(+), 8 deletions(-) > > > > diff --git a/include/libcamera/framebuffer.h b/include/libcamera/framebuffer.h > > index e83825b466aa..653c1a96132f 100644 > > --- a/include/libcamera/framebuffer.h > > +++ b/include/libcamera/framebuffer.h > > @@ -58,7 +58,7 @@ public: > > unsigned int length; > > }; > > > > - FrameBuffer(const std::vector<Plane> &planes, unsigned int cookie = 0); > > + FrameBuffer(Span<const Plane> planes, unsigned int cookie = 0); > > FrameBuffer(std::unique_ptr<Private> d); > > virtual ~FrameBuffer() {} > > > > diff --git a/include/libcamera/internal/framebuffer.h b/include/libcamera/internal/framebuffer.h > > index 97b49d42063f..67b090fc307f 100644 > > --- a/include/libcamera/internal/framebuffer.h > > +++ b/include/libcamera/internal/framebuffer.h > > @@ -12,6 +12,7 @@ > > #include <utility> > > > > #include <libcamera/base/class.h> > > +#include <libcamera/base/span.h> > > > > #include <libcamera/fence.h> > > #include <libcamera/framebuffer.h> > > @@ -23,7 +24,7 @@ class FrameBuffer::Private : public Extensible::Private > > LIBCAMERA_DECLARE_PUBLIC(FrameBuffer) > > > > public: > > - Private(const std::vector<Plane> &planes, uint64_t cookie = 0); > > + Private(Span<const Plane> planes, uint64_t cookie = 0); > > virtual ~Private(); > > > > void setRequest(Request *request) { request_ = request; } > > diff --git a/src/android/mm/cros_frame_buffer_allocator.cpp b/src/android/mm/cros_frame_buffer_allocator.cpp > > index 264c0d481272..7ec116e1500d 100644 > > --- a/src/android/mm/cros_frame_buffer_allocator.cpp > > +++ b/src/android/mm/cros_frame_buffer_allocator.cpp > > @@ -29,7 +29,7 @@ class CrosFrameBufferData : public FrameBuffer::Private > > > > public: > > CrosFrameBufferData(cros::ScopedBufferHandle scopedHandle, > > - const std::vector<FrameBuffer::Plane> &planes) > > + Span<const FrameBuffer::Plane> planes) > > : FrameBuffer::Private(planes), scopedHandle_(std::move(scopedHandle)) > > { > > } > > diff --git a/src/android/mm/generic_frame_buffer_allocator.cpp b/src/android/mm/generic_frame_buffer_allocator.cpp > > index 79625a9a3c75..25ad6b035e73 100644 > > --- a/src/android/mm/generic_frame_buffer_allocator.cpp > > +++ b/src/android/mm/generic_frame_buffer_allocator.cpp > > @@ -35,7 +35,7 @@ class GenericFrameBufferData : public FrameBuffer::Private > > public: > > GenericFrameBufferData(struct alloc_device_t *allocDevice, > > buffer_handle_t handle, > > - const std::vector<FrameBuffer::Plane> &planes) > > + Span<const FrameBuffer::Plane> planes) > > : FrameBuffer::Private(planes), allocDevice_(allocDevice), > > handle_(handle) > > { > > diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp > > index 219db50d6527..cb849b8e40fe 100644 > > --- a/src/libcamera/framebuffer.cpp > > +++ b/src/libcamera/framebuffer.cpp > > @@ -130,9 +130,9 @@ LOG_DEFINE_CATEGORY(Buffer) > > * \param[in] planes The frame memory planes > > * \param[in] cookie Cookie > > */ > > -FrameBuffer::Private::Private(const std::vector<Plane> &planes, uint64_t cookie) > > - : planes_(planes), cookie_(cookie), request_(nullptr), > > - isContiguous_(true) > > +FrameBuffer::Private::Private(Span<const Plane> planes, uint64_t cookie) > > + : planes_(std::begin(planes), std::end(planes)), cookie_(cookie), > > What was the motivation for using `std::{begin,end}()` instead of > `planes.{begin,end}()`? None :-) If you think planes.begin() and planes.end() are better I can update the patch. > Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> > > > + request_(nullptr), isContiguous_(true) > > { > > metadata_.planes_.resize(planes_.size()); > > } > > @@ -315,7 +315,7 @@ ino_t fileDescriptorInode(const SharedFD &fd) > > * \param[in] planes The frame memory planes > > * \param[in] cookie Cookie > > */ > > -FrameBuffer::FrameBuffer(const std::vector<Plane> &planes, unsigned int cookie) > > +FrameBuffer::FrameBuffer(Span<const Plane> planes, unsigned int cookie) > > : FrameBuffer(std::make_unique<Private>(planes, cookie)) > > { > > } > > > > base-commit: aa0a91c48ddb38c302390d5c4899cb9e093ddd24
diff --git a/include/libcamera/framebuffer.h b/include/libcamera/framebuffer.h index e83825b466aa..653c1a96132f 100644 --- a/include/libcamera/framebuffer.h +++ b/include/libcamera/framebuffer.h @@ -58,7 +58,7 @@ public: unsigned int length; }; - FrameBuffer(const std::vector<Plane> &planes, unsigned int cookie = 0); + FrameBuffer(Span<const Plane> planes, unsigned int cookie = 0); FrameBuffer(std::unique_ptr<Private> d); virtual ~FrameBuffer() {} diff --git a/include/libcamera/internal/framebuffer.h b/include/libcamera/internal/framebuffer.h index 97b49d42063f..67b090fc307f 100644 --- a/include/libcamera/internal/framebuffer.h +++ b/include/libcamera/internal/framebuffer.h @@ -12,6 +12,7 @@ #include <utility> #include <libcamera/base/class.h> +#include <libcamera/base/span.h> #include <libcamera/fence.h> #include <libcamera/framebuffer.h> @@ -23,7 +24,7 @@ class FrameBuffer::Private : public Extensible::Private LIBCAMERA_DECLARE_PUBLIC(FrameBuffer) public: - Private(const std::vector<Plane> &planes, uint64_t cookie = 0); + Private(Span<const Plane> planes, uint64_t cookie = 0); virtual ~Private(); void setRequest(Request *request) { request_ = request; } diff --git a/src/android/mm/cros_frame_buffer_allocator.cpp b/src/android/mm/cros_frame_buffer_allocator.cpp index 264c0d481272..7ec116e1500d 100644 --- a/src/android/mm/cros_frame_buffer_allocator.cpp +++ b/src/android/mm/cros_frame_buffer_allocator.cpp @@ -29,7 +29,7 @@ class CrosFrameBufferData : public FrameBuffer::Private public: CrosFrameBufferData(cros::ScopedBufferHandle scopedHandle, - const std::vector<FrameBuffer::Plane> &planes) + Span<const FrameBuffer::Plane> planes) : FrameBuffer::Private(planes), scopedHandle_(std::move(scopedHandle)) { } diff --git a/src/android/mm/generic_frame_buffer_allocator.cpp b/src/android/mm/generic_frame_buffer_allocator.cpp index 79625a9a3c75..25ad6b035e73 100644 --- a/src/android/mm/generic_frame_buffer_allocator.cpp +++ b/src/android/mm/generic_frame_buffer_allocator.cpp @@ -35,7 +35,7 @@ class GenericFrameBufferData : public FrameBuffer::Private public: GenericFrameBufferData(struct alloc_device_t *allocDevice, buffer_handle_t handle, - const std::vector<FrameBuffer::Plane> &planes) + Span<const FrameBuffer::Plane> planes) : FrameBuffer::Private(planes), allocDevice_(allocDevice), handle_(handle) { diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp index 219db50d6527..cb849b8e40fe 100644 --- a/src/libcamera/framebuffer.cpp +++ b/src/libcamera/framebuffer.cpp @@ -130,9 +130,9 @@ LOG_DEFINE_CATEGORY(Buffer) * \param[in] planes The frame memory planes * \param[in] cookie Cookie */ -FrameBuffer::Private::Private(const std::vector<Plane> &planes, uint64_t cookie) - : planes_(planes), cookie_(cookie), request_(nullptr), - isContiguous_(true) +FrameBuffer::Private::Private(Span<const Plane> planes, uint64_t cookie) + : planes_(std::begin(planes), std::end(planes)), cookie_(cookie), + request_(nullptr), isContiguous_(true) { metadata_.planes_.resize(planes_.size()); } @@ -315,7 +315,7 @@ ino_t fileDescriptorInode(const SharedFD &fd) * \param[in] planes The frame memory planes * \param[in] cookie Cookie */ -FrameBuffer::FrameBuffer(const std::vector<Plane> &planes, unsigned int cookie) +FrameBuffer::FrameBuffer(Span<const Plane> planes, unsigned int cookie) : FrameBuffer(std::make_unique<Private>(planes, cookie)) { }
The FrameBuffer constructor takes a list of planes as an std::vector. The caller may stores the planes in a different type of container, resulting in the needless allocation of a temporary vector. Replace it with a span. Suggested-by: Daniel Rákos <daniel.rakos@rastergrid.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- include/libcamera/framebuffer.h | 2 +- include/libcamera/internal/framebuffer.h | 3 ++- src/android/mm/cros_frame_buffer_allocator.cpp | 2 +- src/android/mm/generic_frame_buffer_allocator.cpp | 2 +- src/libcamera/framebuffer.cpp | 8 ++++---- 5 files changed, 9 insertions(+), 8 deletions(-) base-commit: aa0a91c48ddb38c302390d5c4899cb9e093ddd24