[08/11] ipa: libipa: pwl: Add a constructor that moves a Point vector
diff mbox series

Message ID 20240613013944.23344-9-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • ipa: libipa: Vector and Pwl improvements
Related show

Commit Message

Laurent Pinchart June 13, 2024, 1:39 a.m. UTC
The Pwl::Pwl(const std::vector<Point> &) constructor is inefficient as
it makes a copy of the given points vector. Add a second constructor
that takes an rvalue reference to a points vector to provide move
semantics.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/ipa/libipa/pwl.cpp | 11 +++++++++++
 src/ipa/libipa/pwl.h   |  2 ++
 2 files changed, 13 insertions(+)

Comments

Paul Elder June 13, 2024, 7:55 a.m. UTC | #1
On Thu, Jun 13, 2024 at 04:39:41AM +0300, Laurent Pinchart wrote:
> The Pwl::Pwl(const std::vector<Point> &) constructor is inefficient as
> it makes a copy of the given points vector. Add a second constructor
> that takes an rvalue reference to a points vector to provide move
> semantics.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

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

> ---
>  src/ipa/libipa/pwl.cpp | 11 +++++++++++
>  src/ipa/libipa/pwl.h   |  2 ++
>  2 files changed, 13 insertions(+)
> 
> diff --git a/src/ipa/libipa/pwl.cpp b/src/ipa/libipa/pwl.cpp
> index 8b437dd1a650..cf864fbb3889 100644
> --- a/src/ipa/libipa/pwl.cpp
> +++ b/src/ipa/libipa/pwl.cpp
> @@ -114,6 +114,17 @@ Pwl::Pwl(const std::vector<Point> &points)
>  {
>  }
>  
> +/**
> + * \copydoc Pwl::Pwl(const std::vector<Point> &points)
> + *
> + * The contents of the \a points vector is moved to the newly constructed Pwl
> + * instance.
> + */
> +Pwl::Pwl(std::vector<Point> &&points)
> +	: points_(std::move(points))
> +{
> +}
> +
>  /**
>   * \brief Populate the piecewise linear function from yaml data
>   * \param[in] params Yaml data to populate the piecewise linear function with
> diff --git a/src/ipa/libipa/pwl.h b/src/ipa/libipa/pwl.h
> index 028342314fca..8edb4d33dc71 100644
> --- a/src/ipa/libipa/pwl.h
> +++ b/src/ipa/libipa/pwl.h
> @@ -47,6 +47,8 @@ public:
>  
>  	Pwl();
>  	Pwl(const std::vector<Point> &points);
> +	Pwl(std::vector<Point> &&points);
> +
>  	int readYaml(const libcamera::YamlObject &params);
>  
>  	void append(double x, double y, double eps = 1e-6);
Kieran Bingham June 13, 2024, 11:17 a.m. UTC | #2
Quoting Laurent Pinchart (2024-06-13 02:39:41)
> The Pwl::Pwl(const std::vector<Point> &) constructor is inefficient as
> it makes a copy of the given points vector. Add a second constructor
> that takes an rvalue reference to a points vector to provide move
> semantics.
> 

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

> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  src/ipa/libipa/pwl.cpp | 11 +++++++++++
>  src/ipa/libipa/pwl.h   |  2 ++
>  2 files changed, 13 insertions(+)
> 
> diff --git a/src/ipa/libipa/pwl.cpp b/src/ipa/libipa/pwl.cpp
> index 8b437dd1a650..cf864fbb3889 100644
> --- a/src/ipa/libipa/pwl.cpp
> +++ b/src/ipa/libipa/pwl.cpp
> @@ -114,6 +114,17 @@ Pwl::Pwl(const std::vector<Point> &points)
>  {
>  }
>  
> +/**
> + * \copydoc Pwl::Pwl(const std::vector<Point> &points)
> + *
> + * The contents of the \a points vector is moved to the newly constructed Pwl
> + * instance.
> + */
> +Pwl::Pwl(std::vector<Point> &&points)
> +       : points_(std::move(points))
> +{
> +}
> +
>  /**
>   * \brief Populate the piecewise linear function from yaml data
>   * \param[in] params Yaml data to populate the piecewise linear function with
> diff --git a/src/ipa/libipa/pwl.h b/src/ipa/libipa/pwl.h
> index 028342314fca..8edb4d33dc71 100644
> --- a/src/ipa/libipa/pwl.h
> +++ b/src/ipa/libipa/pwl.h
> @@ -47,6 +47,8 @@ public:
>  
>         Pwl();
>         Pwl(const std::vector<Point> &points);
> +       Pwl(std::vector<Point> &&points);
> +
>         int readYaml(const libcamera::YamlObject &params);
>  
>         void append(double x, double y, double eps = 1e-6);
> -- 
> Regards,
> 
> Laurent Pinchart
>

Patch
diff mbox series

diff --git a/src/ipa/libipa/pwl.cpp b/src/ipa/libipa/pwl.cpp
index 8b437dd1a650..cf864fbb3889 100644
--- a/src/ipa/libipa/pwl.cpp
+++ b/src/ipa/libipa/pwl.cpp
@@ -114,6 +114,17 @@  Pwl::Pwl(const std::vector<Point> &points)
 {
 }
 
+/**
+ * \copydoc Pwl::Pwl(const std::vector<Point> &points)
+ *
+ * The contents of the \a points vector is moved to the newly constructed Pwl
+ * instance.
+ */
+Pwl::Pwl(std::vector<Point> &&points)
+	: points_(std::move(points))
+{
+}
+
 /**
  * \brief Populate the piecewise linear function from yaml data
  * \param[in] params Yaml data to populate the piecewise linear function with
diff --git a/src/ipa/libipa/pwl.h b/src/ipa/libipa/pwl.h
index 028342314fca..8edb4d33dc71 100644
--- a/src/ipa/libipa/pwl.h
+++ b/src/ipa/libipa/pwl.h
@@ -47,6 +47,8 @@  public:
 
 	Pwl();
 	Pwl(const std::vector<Point> &points);
+	Pwl(std::vector<Point> &&points);
+
 	int readYaml(const libcamera::YamlObject &params);
 
 	void append(double x, double y, double eps = 1e-6);