Skip to contentSkip to conversation

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

PATCH Applied Masahiro Yamada 2 participants 2 messages May 12, 2020 – May 21, 2020

lore
Share & tools
lore
#0 lore raw

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

Properties are not related to the initialization of interfaces.

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

---

 qom/object.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
qom/object.c +3 -5
index a3ee968b12..e4085d8ae2 100644
@@ -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) {
Signature · 1 line
2.25.1
#1 lore raw
Quoted 30 lines · Masahiro Yamada

Properties are not related to the initialization of interfaces.

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

---

 qom/object.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
qom/object.c +0 -3
index a3ee968b12..e4085d8ae2 100644
@@ -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 {

qom/object.c static void type_initialize(TypeImpl *ti) · line 355

Quoted 10 lines
qom/object.c +3 -2
-        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