Message ID | 20250815113400.20623-7-laurent.pinchart@ideasonboard.com |
---|---|
State | New |
Headers | show |
Series |
|
Related | show |
Hi 2025. 08. 15. 13:33 keltezéssel, Laurent Pinchart írta: > IPA interface structures store copies of data. For members that are not > PODs, such as vectors or strings, the constructors take const references > to a container class storing the data, and copies it internally. This is > inefficient if the caller constructs the container for the sole purpose > of passing it to the IPA interface structure constructor, as it forces a > copy of the data. > > Replace the const reference argument with a plain instance, and move it > in the constructor. This allows getting rid of the data copy if the > caller uses std::move(). Please see https://patchwork.libcamera.org/patch/24066/. Thoughts? Regards, Barnabás Pőcze > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- > .../generators/libcamera_templates/definition_functions.tmpl | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl b/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl > index 8b8509f3ded6..31c70e152d4f 100644 > --- a/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl > +++ b/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl > @@ -36,12 +36,12 @@ public: > > {{struct.mojom_name}}( > {%- for field in struct.fields -%} > -{{"const " if not field|is_pod}}{{field|name}} {{"&" if not field|is_pod}}_{{field.mojom_name}}{{", " if not loop.last}} > +{{field|name}} _{{field.mojom_name}}{{", " if not loop.last}} > {%- endfor -%} > ) > : > {%- for field in struct.fields -%} > -{{" " if loop.first}}{{field.mojom_name}}(_{{field.mojom_name}}){{", " if not loop.last}} > +{{" " if loop.first}}{{field.mojom_name}}({{"std::move(" if not field|is_pod}}_{{field.mojom_name}}{{")" if not field|is_pod}}){{", " if not loop.last}} > {%- endfor %} > { > }
On Fri, Aug 15, 2025 at 01:45:39PM +0200, Barnabás Pőcze wrote: > 2025. 08. 15. 13:33 keltezéssel, Laurent Pinchart írta: > > IPA interface structures store copies of data. For members that are not > > PODs, such as vectors or strings, the constructors take const references > > to a container class storing the data, and copies it internally. This is > > inefficient if the caller constructs the container for the sole purpose > > of passing it to the IPA interface structure constructor, as it forces a > > copy of the data. > > > > Replace the const reference argument with a plain instance, and move it > > in the constructor. This allows getting rid of the data copy if the > > caller uses std::move(). > > Please see https://patchwork.libcamera.org/patch/24066/. Thoughts? Seems possibly better :-) I'll review that. > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > > --- > > .../generators/libcamera_templates/definition_functions.tmpl | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl b/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl > > index 8b8509f3ded6..31c70e152d4f 100644 > > --- a/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl > > +++ b/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl > > @@ -36,12 +36,12 @@ public: > > > > {{struct.mojom_name}}( > > {%- for field in struct.fields -%} > > -{{"const " if not field|is_pod}}{{field|name}} {{"&" if not field|is_pod}}_{{field.mojom_name}}{{", " if not loop.last}} > > +{{field|name}} _{{field.mojom_name}}{{", " if not loop.last}} > > {%- endfor -%} > > ) > > : > > {%- for field in struct.fields -%} > > -{{" " if loop.first}}{{field.mojom_name}}(_{{field.mojom_name}}){{", " if not loop.last}} > > +{{" " if loop.first}}{{field.mojom_name}}({{"std::move(" if not field|is_pod}}_{{field.mojom_name}}{{")" if not field|is_pod}}){{", " if not loop.last}} > > {%- endfor %} > > { > > }
diff --git a/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl b/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl index 8b8509f3ded6..31c70e152d4f 100644 --- a/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl +++ b/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl @@ -36,12 +36,12 @@ public: {{struct.mojom_name}}( {%- for field in struct.fields -%} -{{"const " if not field|is_pod}}{{field|name}} {{"&" if not field|is_pod}}_{{field.mojom_name}}{{", " if not loop.last}} +{{field|name}} _{{field.mojom_name}}{{", " if not loop.last}} {%- endfor -%} ) : {%- for field in struct.fields -%} -{{" " if loop.first}}{{field.mojom_name}}(_{{field.mojom_name}}){{", " if not loop.last}} +{{" " if loop.first}}{{field.mojom_name}}({{"std::move(" if not field|is_pod}}_{{field.mojom_name}}{{")" if not field|is_pod}}){{", " if not loop.last}} {%- endfor %} { }
IPA interface structures store copies of data. For members that are not PODs, such as vectors or strings, the constructors take const references to a container class storing the data, and copies it internally. This is inefficient if the caller constructs the container for the sole purpose of passing it to the IPA interface structure constructor, as it forces a copy of the data. Replace the const reference argument with a plain instance, and move it in the constructor. This allows getting rid of the data copy if the caller uses std::move(). Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- .../generators/libcamera_templates/definition_functions.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)