[RFC,v1,1/7] libcamera: base: bound_method: Strip qualifiers in argument pack
diff mbox series

Message ID 20250924124713.3361707-2-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • libcamera: camera: Add `applyControls()`
Related show

Commit Message

Barnabás Pőcze Sept. 24, 2025, 12:47 p.m. UTC
Having extra qualifiers, especially `const`, simply inhibits optimization
opportunities as it prevents e.g. moving values out of pack object. So
strip the qualifiers.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
 include/libcamera/base/bound_method.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Stefan Klug Oct. 6, 2025, 12:50 p.m. UTC | #1
Hi Barnabás,

Thank you for the patch.

Quoting Barnabás Pőcze (2025-09-24 14:47:06)
> Having extra qualifiers, especially `const`, simply inhibits optimization
> opportunities as it prevents e.g. moving values out of pack object. So
> strip the qualifiers.
> 
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>

I fully trust you on this one :-)
Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>

Cheers,
Stefan

> ---
>  include/libcamera/base/bound_method.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/include/libcamera/base/bound_method.h b/include/libcamera/base/bound_method.h
> index 91fe8b8cb..cb642e0a9 100644
> --- a/include/libcamera/base/bound_method.h
> +++ b/include/libcamera/base/bound_method.h
> @@ -39,7 +39,7 @@ public:
>         {
>         }
>  
> -       std::tuple<typename std::remove_reference_t<Args>...> args_;
> +       std::tuple<std::remove_cv_t<std::remove_reference_t<Args>>...> args_;
>         R ret_;
>  };
>  
> @@ -53,7 +53,7 @@ public:
>         {
>         }
>  
> -       std::tuple<typename std::remove_reference_t<Args>...> args_;
> +       std::tuple<std::remove_cv_t<std::remove_reference_t<Args>>...> args_;
>  };
>  
>  class BoundMethodBase
> -- 
> 2.51.0
>
Kieran Bingham Oct. 7, 2025, 8:38 a.m. UTC | #2
Quoting Stefan Klug (2025-10-06 13:50:16)
> Hi Barnabás,
> 
> Thank you for the patch.
> 
> Quoting Barnabás Pőcze (2025-09-24 14:47:06)
> > Having extra qualifiers, especially `const`, simply inhibits optimization
> > opportunities as it prevents e.g. moving values out of pack object. So
> > strip the qualifiers.
> > 
> > Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
> 
> I fully trust you on this one :-)
> Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>
> 
> Cheers,
> Stefan
> 
> > ---
> >  include/libcamera/base/bound_method.h | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/include/libcamera/base/bound_method.h b/include/libcamera/base/bound_method.h
> > index 91fe8b8cb..cb642e0a9 100644
> > --- a/include/libcamera/base/bound_method.h
> > +++ b/include/libcamera/base/bound_method.h
> > @@ -39,7 +39,7 @@ public:
> >         {
> >         }
> >  
> > -       std::tuple<typename std::remove_reference_t<Args>...> args_;
> > +       std::tuple<std::remove_cv_t<std::remove_reference_t<Args>>...> args_;

While trying to understand the implications of this I also came across
  std::decay - https://en.cppreference.com/w/cpp/types/decay.html

Is that equivalent to what we're trying to achieve here?

And there's also
https://en.cppreference.com/w/cpp/types/remove_cvref.html - but that's
C++20 only...

--
Kieran

> >         R ret_;
> >  };
> >  
> > @@ -53,7 +53,7 @@ public:
> >         {
> >         }
> >  
> > -       std::tuple<typename std::remove_reference_t<Args>...> args_;
> > +       std::tuple<std::remove_cv_t<std::remove_reference_t<Args>>...> args_;
> >  };
> >  
> >  class BoundMethodBase
> > -- 
> > 2.51.0
> >
Barnabás Pőcze Oct. 7, 2025, 10:50 a.m. UTC | #3
2025. 10. 07. 10:38 keltezéssel, Kieran Bingham írta:
> Quoting Stefan Klug (2025-10-06 13:50:16)
>> Hi Barnabás,
>>
>> Thank you for the patch.
>>
>> Quoting Barnabás Pőcze (2025-09-24 14:47:06)
>>> Having extra qualifiers, especially `const`, simply inhibits optimization
>>> opportunities as it prevents e.g. moving values out of pack object. So
>>> strip the qualifiers.
>>>
>>> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
>>
>> I fully trust you on this one :-)
>> Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>
>>
>> Cheers,
>> Stefan
>>
>>> ---
>>>   include/libcamera/base/bound_method.h | 4 ++--
>>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/include/libcamera/base/bound_method.h b/include/libcamera/base/bound_method.h
>>> index 91fe8b8cb..cb642e0a9 100644
>>> --- a/include/libcamera/base/bound_method.h
>>> +++ b/include/libcamera/base/bound_method.h
>>> @@ -39,7 +39,7 @@ public:
>>>          {
>>>          }
>>>   
>>> -       std::tuple<typename std::remove_reference_t<Args>...> args_;
>>> +       std::tuple<std::remove_cv_t<std::remove_reference_t<Args>>...> args_;
> 
> While trying to understand the implications of this I also came across
>    std::decay - https://en.cppreference.com/w/cpp/types/decay.html
> 
> Is that equivalent to what we're trying to achieve here?

That's a good point. I think that is essentially the intention. My only
concern is arrays because those decay into a simple pointer, which kind
of goes against the "copy" behaviour.

And crucially, this part is only used for function calls, so `Args` is
argument types. Those cannot be arrays or functions. So in that case
`std::decay` is equivalent to `std::remove_cvref`.


Regards,
Barnabás Pőcze

> 
> And there's also
> https://en.cppreference.com/w/cpp/types/remove_cvref.html - but that's
> C++20 only...
> 
> --
> Kieran
> 
>>>          R ret_;
>>>   };
>>>   
>>> @@ -53,7 +53,7 @@ public:
>>>          {
>>>          }
>>>   
>>> -       std::tuple<typename std::remove_reference_t<Args>...> args_;
>>> +       std::tuple<std::remove_cv_t<std::remove_reference_t<Args>>...> args_;
>>>   };
>>>   
>>>   class BoundMethodBase
>>> -- 
>>> 2.51.0
>>>
Kieran Bingham Oct. 7, 2025, 11:16 a.m. UTC | #4
Quoting Barnabás Pőcze (2025-10-07 11:50:44)
> 2025. 10. 07. 10:38 keltezéssel, Kieran Bingham írta:
> > Quoting Stefan Klug (2025-10-06 13:50:16)
> >> Hi Barnabás,
> >>
> >> Thank you for the patch.
> >>
> >> Quoting Barnabás Pőcze (2025-09-24 14:47:06)
> >>> Having extra qualifiers, especially `const`, simply inhibits optimization
> >>> opportunities as it prevents e.g. moving values out of pack object. So
> >>> strip the qualifiers.
> >>>
> >>> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
> >>
> >> I fully trust you on this one :-)
> >> Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>
> >>
> >> Cheers,
> >> Stefan
> >>
> >>> ---
> >>>   include/libcamera/base/bound_method.h | 4 ++--
> >>>   1 file changed, 2 insertions(+), 2 deletions(-)
> >>>
> >>> diff --git a/include/libcamera/base/bound_method.h b/include/libcamera/base/bound_method.h
> >>> index 91fe8b8cb..cb642e0a9 100644
> >>> --- a/include/libcamera/base/bound_method.h
> >>> +++ b/include/libcamera/base/bound_method.h
> >>> @@ -39,7 +39,7 @@ public:
> >>>          {
> >>>          }
> >>>   
> >>> -       std::tuple<typename std::remove_reference_t<Args>...> args_;
> >>> +       std::tuple<std::remove_cv_t<std::remove_reference_t<Args>>...> args_;
> > 
> > While trying to understand the implications of this I also came across
> >    std::decay - https://en.cppreference.com/w/cpp/types/decay.html
> > 
> > Is that equivalent to what we're trying to achieve here?
> 
> That's a good point. I think that is essentially the intention. My only
> concern is arrays because those decay into a simple pointer, which kind
> of goes against the "copy" behaviour.
> 
> And crucially, this part is only used for function calls, so `Args` is
> argument types. Those cannot be arrays or functions. So in that case
> `std::decay` is equivalent to `std::remove_cvref`.

Well, I think I understand the intent now so which ever way you choose
on this for your best/preferred fit:

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

> Regards,
> Barnabás Pőcze
> 
> > 
> > And there's also
> > https://en.cppreference.com/w/cpp/types/remove_cvref.html - but that's
> > C++20 only...
> > 
> > --
> > Kieran
> > 
> >>>          R ret_;
> >>>   };
> >>>   
> >>> @@ -53,7 +53,7 @@ public:
> >>>          {
> >>>          }
> >>>   
> >>> -       std::tuple<typename std::remove_reference_t<Args>...> args_;
> >>> +       std::tuple<std::remove_cv_t<std::remove_reference_t<Args>>...> args_;
> >>>   };
> >>>   
> >>>   class BoundMethodBase
> >>> -- 
> >>> 2.51.0
> >>>
>

Patch
diff mbox series

diff --git a/include/libcamera/base/bound_method.h b/include/libcamera/base/bound_method.h
index 91fe8b8cb..cb642e0a9 100644
--- a/include/libcamera/base/bound_method.h
+++ b/include/libcamera/base/bound_method.h
@@ -39,7 +39,7 @@  public:
 	{
 	}
 
-	std::tuple<typename std::remove_reference_t<Args>...> args_;
+	std::tuple<std::remove_cv_t<std::remove_reference_t<Args>>...> args_;
 	R ret_;
 };
 
@@ -53,7 +53,7 @@  public:
 	{
 	}
 
-	std::tuple<typename std::remove_reference_t<Args>...> args_;
+	std::tuple<std::remove_cv_t<std::remove_reference_t<Args>>...> args_;
 };
 
 class BoundMethodBase