diff mbox series

[3/3] qom: Simplify and merge pointer property getters/setters

Message ID 20201009191520.1799419-4-ehabkost@redhat.com
State New
Headers show
Series qom: Simplify pointer property getters/setters | expand

Commit Message

Eduardo Habkost Oct. 9, 2020, 7:15 p.m. UTC
Both the property getter and setter for pointer properties can
simply call the visitor functions directly, instead of making
extra copies and requiring additional logic.

Remove the extra copying logic, and merge the getter and setter
functions in object_visit_uint*_ptr() accessors.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 qom/object.c | 114 ++++++++++-----------------------------------------
 1 file changed, 22 insertions(+), 92 deletions(-)

Comments

Eric Blake Oct. 9, 2020, 8:02 p.m. UTC | #1
On 10/9/20 2:15 PM, Eduardo Habkost wrote:
> Both the property getter and setter for pointer properties can
> simply call the visitor functions directly, instead of making
> extra copies and requiring additional logic.
> 
> Remove the extra copying logic, and merge the getter and setter
> functions in object_visit_uint*_ptr() accessors.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  qom/object.c | 114 ++++++++++-----------------------------------------
>  1 file changed, 22 insertions(+), 92 deletions(-)
> 
> diff --git a/qom/object.c b/qom/object.c
> index 6b4dfc279a..3b343fd118 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -2496,119 +2496,57 @@ static void *pointer_property_get_ptr(Object *obj, PointerProperty *prop)
>      }
>  }
>  
> -static void property_get_uint8_ptr(Object *obj, Visitor *v, const char *name,
> +static void property_visit_uint8_ptr(Object *obj, Visitor *v, const char *name,
>                                     void *opaque, Error **errp)

Indentation is now off.  Several instances.
diff mbox series

Patch

diff --git a/qom/object.c b/qom/object.c
index 6b4dfc279a..3b343fd118 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -2496,119 +2496,57 @@  static void *pointer_property_get_ptr(Object *obj, PointerProperty *prop)
     }
 }
 
-static void property_get_uint8_ptr(Object *obj, Visitor *v, const char *name,
+static void property_visit_uint8_ptr(Object *obj, Visitor *v, const char *name,
                                    void *opaque, Error **errp)
 {
     PointerProperty *prop = opaque;
     uint8_t *field = pointer_property_get_ptr(obj, prop);
-    uint8_t value = *field;
-    visit_type_uint8(v, name, &value, errp);
+    visit_type_uint8(v, name, field, errp);
 }
 
-static void property_set_uint8_ptr(Object *obj, Visitor *v, const char *name,
-                                   void *opaque, Error **errp)
-{
-    PointerProperty *prop = opaque;
-    uint8_t *field = pointer_property_get_ptr(obj, prop);
-    uint8_t value;
-
-    if (!visit_type_uint8(v, name, &value, errp)) {
-        return;
-    }
-
-    *field = value;
-}
-
-static void property_get_uint16_ptr(Object *obj, Visitor *v, const char *name,
+static void property_visit_uint16_ptr(Object *obj, Visitor *v, const char *name,
                                     void *opaque, Error **errp)
 {
     PointerProperty *prop = opaque;
     uint16_t *field = pointer_property_get_ptr(obj, prop);
-    uint16_t value = *field;
-    visit_type_uint16(v, name, &value, errp);
-}
-
-static void property_set_uint16_ptr(Object *obj, Visitor *v, const char *name,
-                                    void *opaque, Error **errp)
-{
-    PointerProperty *prop = opaque;
-    uint16_t *field = pointer_property_get_ptr(obj, prop);
-    uint16_t value;
-
-    if (!visit_type_uint16(v, name, &value, errp)) {
-        return;
-    }
-
-    *field = value;
+    visit_type_uint16(v, name, field, errp);
 }
 
-static void property_get_uint32_ptr(Object *obj, Visitor *v, const char *name,
+static void property_visit_uint32_ptr(Object *obj, Visitor *v, const char *name,
                                     void *opaque, Error **errp)
 {
     PointerProperty *prop = opaque;
     uint32_t *field = pointer_property_get_ptr(obj, prop);
-    uint32_t value = *field;
-    visit_type_uint32(v, name, &value, errp);
+    visit_type_uint32(v, name, field, errp);
 }
 
-static void property_set_uint32_ptr(Object *obj, Visitor *v, const char *name,
-                                    void *opaque, Error **errp)
-{
-    PointerProperty *prop = opaque;
-    uint32_t *field = pointer_property_get_ptr(obj, prop);
-    uint32_t value;
-
-    if (!visit_type_uint32(v, name, &value, errp)) {
-        return;
-    }
-
-    *field = value;
-}
-
-static void property_get_uint64_ptr(Object *obj, Visitor *v, const char *name,
+static void property_visit_uint64_ptr(Object *obj, Visitor *v, const char *name,
                                     void *opaque, Error **errp)
 {
     PointerProperty *prop = opaque;
     uint64_t *field = pointer_property_get_ptr(obj, prop);
-    uint64_t value = *field;
-    visit_type_uint64(v, name, &value, errp);
-}
-
-static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name,
-                                    void *opaque, Error **errp)
-{
-    PointerProperty *prop = opaque;
-    uint64_t *field = pointer_property_get_ptr(obj, prop);
-    uint64_t value;
-
-    if (!visit_type_uint64(v, name, &value, errp)) {
-        return;
-    }
-
-    *field = value;
+    visit_type_uint64(v, name, field, errp);
 }
 
 static ObjectProperty *
 object_property_add_uint_ptr(Object *obj, const char *name,
                             const char *type,
-                            ObjectPropertyAccessor getter,
-                            ObjectPropertyAccessor setter,
+                            ObjectPropertyAccessor accessor,
                             ObjectPropertyFlags flags,
                             void *ptr)
 {
     PointerProperty *prop = g_new0(PointerProperty, 1);
     prop->ptr = ptr;
     return object_property_add(obj, name, type,
-                               (flags & OBJ_PROP_FLAG_READ) ? getter : NULL,
-                               (flags & OBJ_PROP_FLAG_WRITE) ? setter : NULL,
+                               (flags & OBJ_PROP_FLAG_READ) ? accessor : NULL,
+                               (flags & OBJ_PROP_FLAG_WRITE) ? accessor : NULL,
                                NULL, (void *)prop);
 }
 
 static ObjectProperty *
 object_class_property_add_uint_ptr(ObjectClass *oc, const char *name,
                                    const char *type,
-                                   ObjectPropertyAccessor getter,
-                                   ObjectPropertyAccessor setter,
+                                   ObjectPropertyAccessor accessor,
                                    ObjectPropertyFlags flags,
                                    ptrdiff_t offset)
 {
@@ -2616,8 +2554,8 @@  object_class_property_add_uint_ptr(ObjectClass *oc, const char *name,
     prop->is_offset = true;
     prop->offset = offset;
     return object_class_property_add(oc, name, type,
-                                     (flags & OBJ_PROP_FLAG_READ) ? getter : NULL,
-                                     (flags & OBJ_PROP_FLAG_WRITE) ? setter : NULL,
+                                     (flags & OBJ_PROP_FLAG_READ) ? accessor : NULL,
+                                     (flags & OBJ_PROP_FLAG_WRITE) ? accessor : NULL,
                                      NULL, (void *)prop);
 }
 
@@ -2627,8 +2565,7 @@  object_property_add_uint8_ptr(Object *obj, const char *name,
                               ObjectPropertyFlags flags)
 {
     return object_property_add_uint_ptr(obj, name, "uint8",
-                                        property_get_uint8_ptr,
-                                        property_set_uint8_ptr,
+                                        property_visit_uint8_ptr,
                                         flags,
                                         (void *)v);
 }
@@ -2639,8 +2576,7 @@  object_class_property_add_uint8_ptr(ObjectClass *klass, const char *name,
                                     ObjectPropertyFlags flags)
 {
     return object_class_property_add_uint_ptr(klass, name, "uint8",
-                                              property_get_uint8_ptr,
-                                              property_set_uint8_ptr,
+                                              property_visit_uint8_ptr,
                                               flags, offset);
 }
 
@@ -2650,8 +2586,7 @@  object_property_add_uint16_ptr(Object *obj, const char *name,
                                ObjectPropertyFlags flags)
 {
     return object_property_add_uint_ptr(obj, name, "uint16",
-                                        property_get_uint16_ptr,
-                                        property_set_uint16_ptr,
+                                        property_visit_uint16_ptr,
                                         flags,
                                         (void *)v);
 }
@@ -2662,8 +2597,7 @@  object_class_property_add_uint16_ptr(ObjectClass *klass, const char *name,
                                      ObjectPropertyFlags flags)
 {
     return object_class_property_add_uint_ptr(klass, name, "uint16",
-                                              property_get_uint16_ptr,
-                                              property_set_uint16_ptr,
+                                              property_visit_uint16_ptr,
                                               flags, offset);
 }
 
@@ -2673,8 +2607,7 @@  object_property_add_uint32_ptr(Object *obj, const char *name,
                                ObjectPropertyFlags flags)
 {
     return object_property_add_uint_ptr(obj, name, "uint32",
-                                        property_get_uint32_ptr,
-                                        property_set_uint32_ptr,
+                                        property_visit_uint32_ptr,
                                         flags,
                                         (void *)v);
 }
@@ -2685,8 +2618,7 @@  object_class_property_add_uint32_ptr(ObjectClass *klass, const char *name,
                                      ObjectPropertyFlags flags)
 {
     return object_class_property_add_uint_ptr(klass, name, "uint32",
-                                              property_get_uint32_ptr,
-                                              property_set_uint32_ptr,
+                                              property_visit_uint32_ptr,
                                               flags, offset);
 }
 
@@ -2696,8 +2628,7 @@  object_property_add_uint64_ptr(Object *obj, const char *name,
                                ObjectPropertyFlags flags)
 {
     return object_property_add_uint_ptr(obj, name, "uint64",
-                                        property_get_uint64_ptr,
-                                        property_set_uint64_ptr,
+                                        property_visit_uint64_ptr,
                                         flags,
                                         (void *)v);
 }
@@ -2708,8 +2639,7 @@  object_class_property_add_uint64_ptr(ObjectClass *klass, const char *name,
                                      ObjectPropertyFlags flags)
 {
     return object_class_property_add_uint_ptr(klass, name, "uint64",
-                                              property_get_uint64_ptr,
-                                              property_set_uint64_ptr,
+                                              property_visit_uint64_ptr,
                                               flags, offset);
 }