| Message ID | 20251014142427.3107490-2-stefan.klug@ideasonboard.com |
|---|---|
| State | New |
| Headers | show |
| Series |
|
| Related | show |
2025. 10. 14. 16:24 keltezéssel, Stefan Klug írta: > Add a swap() function to easily swap the contents of two PWLs. > > Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> > --- It looks OK, although I believe all use-cases in this patch series can be replaced with the already generated move assignment operator. Maybe I am missing some other reason? But if it is need: Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> > src/ipa/libipa/pwl.cpp | 6 ++++++ > src/ipa/libipa/pwl.h | 1 + > 2 files changed, 7 insertions(+) > > diff --git a/src/ipa/libipa/pwl.cpp b/src/ipa/libipa/pwl.cpp > index 69a9334112e8..1858ab37b101 100644 > --- a/src/ipa/libipa/pwl.cpp > +++ b/src/ipa/libipa/pwl.cpp > @@ -169,6 +169,12 @@ void Pwl::prepend(double x, double y, const double eps) > * \return The number of points in the piecewise linear function > */ > > +/** > + * \fn Pwl::swap(Pwl &other) > + * \brief Swap the contents with another PWL > + * \param[in] other The PWL to swap with > + */ > + > /** > * \brief Get the domain of the piecewise linear function > * \return An interval representing the domain > diff --git a/src/ipa/libipa/pwl.h b/src/ipa/libipa/pwl.h > index c1496c300ee0..add20b5867af 100644 > --- a/src/ipa/libipa/pwl.h > +++ b/src/ipa/libipa/pwl.h > @@ -51,6 +51,7 @@ public: > bool empty() const { return points_.empty(); } > void clear() { points_.clear(); } > size_t size() const { return points_.size(); } > + void swap(Pwl &other) { points_.swap(other.points_); } > > Interval domain() const; > Interval range() const;
Hi Stefan - thanks for the patches and fixing my mistakes :) On 14/10/2025 15:24, Stefan Klug wrote: > Add a swap() function to easily swap the contents of two PWLs. > > Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> > --- Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com> > src/ipa/libipa/pwl.cpp | 6 ++++++ > src/ipa/libipa/pwl.h | 1 + > 2 files changed, 7 insertions(+) > > diff --git a/src/ipa/libipa/pwl.cpp b/src/ipa/libipa/pwl.cpp > index 69a9334112e8..1858ab37b101 100644 > --- a/src/ipa/libipa/pwl.cpp > +++ b/src/ipa/libipa/pwl.cpp > @@ -169,6 +169,12 @@ void Pwl::prepend(double x, double y, const double eps) > * \return The number of points in the piecewise linear function > */ > > +/** > + * \fn Pwl::swap(Pwl &other) > + * \brief Swap the contents with another PWL > + * \param[in] other The PWL to swap with > + */ > + > /** > * \brief Get the domain of the piecewise linear function > * \return An interval representing the domain > diff --git a/src/ipa/libipa/pwl.h b/src/ipa/libipa/pwl.h > index c1496c300ee0..add20b5867af 100644 > --- a/src/ipa/libipa/pwl.h > +++ b/src/ipa/libipa/pwl.h > @@ -51,6 +51,7 @@ public: > bool empty() const { return points_.empty(); } > void clear() { points_.clear(); } > size_t size() const { return points_.size(); } > + void swap(Pwl &other) { points_.swap(other.points_); } > > Interval domain() const; > Interval range() const;
On Tue, Oct 14, 2025 at 04:38:27PM +0200, Barnabás Pőcze wrote: > 2025. 10. 14. 16:24 keltezéssel, Stefan Klug írta: > > Add a swap() function to easily swap the contents of two PWLs. > > > > Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> > > --- > > It looks OK, although I believe all use-cases in this patch series > can be replaced with the already generated move assignment operator. > Maybe I am missing some other reason? With std::swap() then I suppose ? I agree, that could be better. > But if it is need: > > Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> > > > src/ipa/libipa/pwl.cpp | 6 ++++++ > > src/ipa/libipa/pwl.h | 1 + > > 2 files changed, 7 insertions(+) > > > > diff --git a/src/ipa/libipa/pwl.cpp b/src/ipa/libipa/pwl.cpp > > index 69a9334112e8..1858ab37b101 100644 > > --- a/src/ipa/libipa/pwl.cpp > > +++ b/src/ipa/libipa/pwl.cpp > > @@ -169,6 +169,12 @@ void Pwl::prepend(double x, double y, const double eps) > > * \return The number of points in the piecewise linear function > > */ > > > > +/** > > + * \fn Pwl::swap(Pwl &other) > > + * \brief Swap the contents with another PWL > > + * \param[in] other The PWL to swap with > > + */ > > + > > /** > > * \brief Get the domain of the piecewise linear function > > * \return An interval representing the domain > > diff --git a/src/ipa/libipa/pwl.h b/src/ipa/libipa/pwl.h > > index c1496c300ee0..add20b5867af 100644 > > --- a/src/ipa/libipa/pwl.h > > +++ b/src/ipa/libipa/pwl.h > > @@ -51,6 +51,7 @@ public: > > bool empty() const { return points_.empty(); } > > void clear() { points_.clear(); } > > size_t size() const { return points_.size(); } > > + void swap(Pwl &other) { points_.swap(other.points_); } > > > > Interval domain() const; > > Interval range() const;
Hi 2025. 11. 02. 23:06 keltezéssel, Laurent Pinchart írta: > On Tue, Oct 14, 2025 at 04:38:27PM +0200, Barnabás Pőcze wrote: >> 2025. 10. 14. 16:24 keltezéssel, Stefan Klug írta: >>> Add a swap() function to easily swap the contents of two PWLs. >>> >>> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> >>> --- >> >> It looks OK, although I believe all use-cases in this patch series >> can be replaced with the already generated move assignment operator. >> Maybe I am missing some other reason? > > With std::swap() then I suppose ? I agree, that could be better. I don't think std::swap() is needed. Just someMember_ = std::move(someLocal); is enough to cover all use cases as far as I can see. Regards, Barnabás Pőcze > >> But if it is need: >> >> Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> >> >>> src/ipa/libipa/pwl.cpp | 6 ++++++ >>> src/ipa/libipa/pwl.h | 1 + >>> 2 files changed, 7 insertions(+) >>> >>> diff --git a/src/ipa/libipa/pwl.cpp b/src/ipa/libipa/pwl.cpp >>> index 69a9334112e8..1858ab37b101 100644 >>> --- a/src/ipa/libipa/pwl.cpp >>> +++ b/src/ipa/libipa/pwl.cpp >>> @@ -169,6 +169,12 @@ void Pwl::prepend(double x, double y, const double eps) >>> * \return The number of points in the piecewise linear function >>> */ >>> >>> +/** >>> + * \fn Pwl::swap(Pwl &other) >>> + * \brief Swap the contents with another PWL >>> + * \param[in] other The PWL to swap with >>> + */ >>> + >>> /** >>> * \brief Get the domain of the piecewise linear function >>> * \return An interval representing the domain >>> diff --git a/src/ipa/libipa/pwl.h b/src/ipa/libipa/pwl.h >>> index c1496c300ee0..add20b5867af 100644 >>> --- a/src/ipa/libipa/pwl.h >>> +++ b/src/ipa/libipa/pwl.h >>> @@ -51,6 +51,7 @@ public: >>> bool empty() const { return points_.empty(); } >>> void clear() { points_.clear(); } >>> size_t size() const { return points_.size(); } >>> + void swap(Pwl &other) { points_.swap(other.points_); } >>> >>> Interval domain() const; >>> Interval range() const; >
diff --git a/src/ipa/libipa/pwl.cpp b/src/ipa/libipa/pwl.cpp index 69a9334112e8..1858ab37b101 100644 --- a/src/ipa/libipa/pwl.cpp +++ b/src/ipa/libipa/pwl.cpp @@ -169,6 +169,12 @@ void Pwl::prepend(double x, double y, const double eps) * \return The number of points in the piecewise linear function */ +/** + * \fn Pwl::swap(Pwl &other) + * \brief Swap the contents with another PWL + * \param[in] other The PWL to swap with + */ + /** * \brief Get the domain of the piecewise linear function * \return An interval representing the domain diff --git a/src/ipa/libipa/pwl.h b/src/ipa/libipa/pwl.h index c1496c300ee0..add20b5867af 100644 --- a/src/ipa/libipa/pwl.h +++ b/src/ipa/libipa/pwl.h @@ -51,6 +51,7 @@ public: bool empty() const { return points_.empty(); } void clear() { points_.clear(); } size_t size() const { return points_.size(); } + void swap(Pwl &other) { points_.swap(other.points_); } Interval domain() const; Interval range() const;
Add a swap() function to easily swap the contents of two PWLs. Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> --- src/ipa/libipa/pwl.cpp | 6 ++++++ src/ipa/libipa/pwl.h | 1 + 2 files changed, 7 insertions(+)