From c905102d82eb1ad2b75899f2ab3650a0285e18d9 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Sun, 23 Jun 2024 15:54:45 +0200 Subject: [PATCH 1/6] Pass value by const reference in the relation setter --- python/templates/macros/declarations.jinja2 | 2 +- python/templates/macros/implementations.jinja2 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/templates/macros/declarations.jinja2 b/python/templates/macros/declarations.jinja2 index 5ef5b8707..a329c599a 100644 --- a/python/templates/macros/declarations.jinja2 +++ b/python/templates/macros/declarations.jinja2 @@ -121,7 +121,7 @@ {% macro single_relation_setters(relations, get_syntax) %} {% for relation in relations %} /// Set the {{ relation.description }} - void {{ relation.setter_name(get_syntax) }}({{ relation.full_type }} value); + void {{ relation.setter_name(get_syntax) }}(const {{ relation.full_type }}& value); {% endfor %} {%- endmacro %} diff --git a/python/templates/macros/implementations.jinja2 b/python/templates/macros/implementations.jinja2 index d3f367fdf..6bac87ae0 100644 --- a/python/templates/macros/implementations.jinja2 +++ b/python/templates/macros/implementations.jinja2 @@ -123,7 +123,7 @@ const {{ relation.full_type }} {{ class_type }}::{{ relation.getter_name(get_syn {% macro single_relation_setters(class, relations, get_syntax, prefix='') %} {% set class_type = prefix + class.bare_type %} {% for relation in relations %} -void {{ class_type }}::{{ relation.setter_name(get_syntax) }}({{ relation.full_type }} value) { +void {{ class_type }}::{{ relation.setter_name(get_syntax) }}(const {{ relation.full_type }}& value) { if (m_obj->m_{{ relation.name }}) { delete m_obj->m_{{ relation.name }}; } From 1c3f6fb5054f005b869861e127a86d416cb4748e Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Sun, 23 Jun 2024 16:05:58 +0200 Subject: [PATCH 2/6] Don't check for nullptr before delete --- python/templates/Obj.cc.jinja2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/templates/Obj.cc.jinja2 b/python/templates/Obj.cc.jinja2 index 1f935ca46..b127fcce7 100644 --- a/python/templates/Obj.cc.jinja2 +++ b/python/templates/Obj.cc.jinja2 @@ -57,7 +57,7 @@ {%- endwith %} {% for relation in OneToOneRelations %} - if (m_{{ relation.name }}) delete m_{{ relation.name }}; + delete m_{{ relation.name }}; {% endfor %} } {%- endif %} From 8359ef6d276b5b15b50ea45200cc3397a49beadc Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Sun, 23 Jun 2024 16:07:37 +0200 Subject: [PATCH 3/6] Remove unnecessary include --- python/templates/macros/utils.jinja2 | 1 - 1 file changed, 1 deletion(-) diff --git a/python/templates/macros/utils.jinja2 b/python/templates/macros/utils.jinja2 index 56511a6fe..c2686222a 100644 --- a/python/templates/macros/utils.jinja2 +++ b/python/templates/macros/utils.jinja2 @@ -30,7 +30,6 @@ namespace {{ nsp }} { #include "{{ incfolder }}Mutable{{ type }}.h" #include "{{ incfolder }}{{ type }}Obj.h" #include "{{ incfolder }}{{ type }}Data.h" -#include "{{ incfolder }}{{ type }}Collection.h" {%- endmacro %} From 53533bfa6cfec75963b16255d39f2440c36ec972 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Sun, 23 Jun 2024 16:14:11 +0200 Subject: [PATCH 4/6] Remove unnecessary ostream --- python/templates/MutableObject.cc.jinja2 | 2 -- 1 file changed, 2 deletions(-) diff --git a/python/templates/MutableObject.cc.jinja2 b/python/templates/MutableObject.cc.jinja2 index d94b4f32c..329a0f830 100644 --- a/python/templates/MutableObject.cc.jinja2 +++ b/python/templates/MutableObject.cc.jinja2 @@ -12,8 +12,6 @@ #include "nlohmann/json.hpp" #endif -#include - {{ utils.namespace_open(class.namespace) }} {{ macros.constructors_destructors(class.bare_type, Members, multi_relations=OneToManyRelations + VectorMembers, prefix='Mutable') }} From d2e40a945c74ce8316817c8be9b2943ea2df273b Mon Sep 17 00:00:00 2001 From: Juan Miguel Carceller <22276694+jmcarcell@users.noreply.github.com> Date: Mon, 24 Jun 2024 08:01:09 +0200 Subject: [PATCH 5/6] Remove another check before delete Co-authored-by: Mateusz Jakub Fila <37295697+m-fila@users.noreply.github.com> --- python/templates/macros/implementations.jinja2 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/python/templates/macros/implementations.jinja2 b/python/templates/macros/implementations.jinja2 index 6bac87ae0..fddd1be3e 100644 --- a/python/templates/macros/implementations.jinja2 +++ b/python/templates/macros/implementations.jinja2 @@ -124,9 +124,7 @@ const {{ relation.full_type }} {{ class_type }}::{{ relation.getter_name(get_syn {% set class_type = prefix + class.bare_type %} {% for relation in relations %} void {{ class_type }}::{{ relation.setter_name(get_syntax) }}(const {{ relation.full_type }}& value) { - if (m_obj->m_{{ relation.name }}) { - delete m_obj->m_{{ relation.name }}; - } + delete m_obj->m_{{ relation.name }}; m_obj->m_{{ relation.name }} = new {{ relation.full_type }}(value); } From 390f2712d0abb05b367921a101cc7661de2e93b4 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 24 Jun 2024 11:33:19 +0200 Subject: [PATCH 6/6] Remove if - else --- python/templates/macros/implementations.jinja2 | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/python/templates/macros/implementations.jinja2 b/python/templates/macros/implementations.jinja2 index fddd1be3e..c1c8221bd 100644 --- a/python/templates/macros/implementations.jinja2 +++ b/python/templates/macros/implementations.jinja2 @@ -180,10 +180,7 @@ podio::RelationRange<{{ relation.full_type }}> {{ class_type }}::{{ relation.get {% macro common_object_funcs(class, prefix='') %} {% set full_type = prefix + class.bare_type %} bool {{ full_type }}::isAvailable() const { - if (m_obj) { - return true; - } - return false; + return m_obj; } const podio::ObjectID {{ full_type }}::getObjectID() const {