[PATCH] qom/object: factor out the initialization of hash table of properties

Masahiro Yamada posted 1 patch 4 years ago
Test docker-mingw@fedora passed
Test checkpatch passed
Test asan passed
Test docker-quick@centos7 passed
Test FreeBSD passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20200512172615.2291999-1-masahiroy@kernel.org
Maintainers: Eduardo Habkost <ehabkost@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>
qom/object.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
[PATCH] qom/object: factor out the initialization of hash table of properties
Posted by Masahiro Yamada 4 years ago
Properties are not related to the initialization of interfaces.

The initialization of the hash table can be moved after the if-block,
and unified.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 qom/object.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/qom/object.c b/qom/object.c
index a3ee968b12..e4085d8ae2 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -316,8 +316,6 @@ static void type_initialize(TypeImpl *ti)
         g_assert(parent->instance_size <= ti->instance_size);
         memcpy(ti->class, parent->class, parent->class_size);
         ti->class->interfaces = NULL;
-        ti->class->properties = g_hash_table_new_full(
-            g_str_hash, g_str_equal, NULL, object_property_free);
 
         for (e = parent->class->interfaces; e; e = e->next) {
             InterfaceClass *iface = e->data;
@@ -347,11 +345,11 @@ static void type_initialize(TypeImpl *ti)
 
             type_initialize_interface(ti, t, t);
         }
-    } else {
-        ti->class->properties = g_hash_table_new_full(
-            g_str_hash, g_str_equal, NULL, object_property_free);
     }
 
+    ti->class->properties = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+                                                  object_property_free);
+
     ti->class->type = ti;
 
     while (parent) {
-- 
2.25.1


Re: [PATCH] qom/object: factor out the initialization of hash table of properties
Posted by Paolo Bonzini 3 years, 12 months ago
On 12/05/20 19:26, Masahiro Yamada wrote:
> Properties are not related to the initialization of interfaces.
> 
> The initialization of the hash table can be moved after the if-block,
> and unified.
> 
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
> 
>  qom/object.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/qom/object.c b/qom/object.c
> index a3ee968b12..e4085d8ae2 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -316,8 +316,6 @@ static void type_initialize(TypeImpl *ti)
>          g_assert(parent->instance_size <= ti->instance_size);
>          memcpy(ti->class, parent->class, parent->class_size);
>          ti->class->interfaces = NULL;
> -        ti->class->properties = g_hash_table_new_full(
> -            g_str_hash, g_str_equal, NULL, object_property_free);
>  
>          for (e = parent->class->interfaces; e; e = e->next) {
>              InterfaceClass *iface = e->data;
> @@ -347,11 +345,11 @@ static void type_initialize(TypeImpl *ti)
>  
>              type_initialize_interface(ti, t, t);
>          }
> -    } else {
> -        ti->class->properties = g_hash_table_new_full(
> -            g_str_hash, g_str_equal, NULL, object_property_free);
>      }
>  
> +    ti->class->properties = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
> +                                                  object_property_free);
> +
>      ti->class->type = ti;
>  
>      while (parent) {
> 

Queued, thanks.

Paolo