qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH qom-next] qom: Introduce object_property_is_{child, link}()
@ 2012-05-26 23:19 Andreas Färber
  2012-05-28  6:47 ` Paolo Bonzini
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Färber @ 2012-05-26 23:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Alexander Barabash, Andreas Färber,
	Anthony Liguori

Avoids hardcoding partial string comparisons.

Signed-off-by: Alexander Barabash <alexander_barabash@mentor.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 qom/object.c |   22 ++++++++++++++++------
 1 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/qom/object.c b/qom/object.c
index 173835b..00bb3b0 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -305,6 +305,16 @@ void object_initialize(void *data, const char *typename)
     object_initialize_with_type(data, type);
 }
 
+static inline bool object_property_is_child(ObjectProperty *prop)
+{
+    return strstart(prop->type, "child<", NULL);
+}
+
+static inline bool object_property_is_link(ObjectProperty *prop)
+{
+    return strstart(prop->type, "link<", NULL);
+}
+
 static void object_property_del_all(Object *obj)
 {
     while (!QTAILQ_EMPTY(&obj->properties)) {
@@ -327,7 +337,7 @@ static void object_property_del_child(Object *obj, Object *child, Error **errp)
     ObjectProperty *prop;
 
     QTAILQ_FOREACH(prop, &obj->properties, node) {
-        if (strstart(prop->type, "child<", NULL) && prop->opaque == child) {
+        if (object_property_is_child(prop) && prop->opaque == child) {
             object_property_del(obj, prop->name, errp);
             break;
         }
@@ -600,7 +610,7 @@ int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque),
     int ret = 0;
 
     QTAILQ_FOREACH(prop, &obj->properties, node) {
-        if (strstart(prop->type, "child<", NULL)) {
+        if (object_property_is_child(prop)) {
             ret = fn(prop->opaque, opaque);
             if (ret != 0) {
                 break;
@@ -1022,7 +1032,7 @@ gchar *object_get_canonical_path(Object *obj)
         g_assert(obj->parent != NULL);
 
         QTAILQ_FOREACH(prop, &obj->parent->properties, node) {
-            if (!strstart(prop->type, "child<", NULL)) {
+            if (!object_property_is_child(prop)) {
                 continue;
             }
 
@@ -1056,9 +1066,9 @@ Object *object_resolve_path_component(Object *parent, gchar *part)
         return NULL;
     }
 
-    if (strstart(prop->type, "link<", NULL)) {
+    if (object_property_is_link(prop)) {
         return *(Object **)prop->opaque;
-    } else if (strstart(prop->type, "child<", NULL)) {
+    } else if (object_property_is_child(prop)) {
         return prop->opaque;
     } else {
         return NULL;
@@ -1101,7 +1111,7 @@ static Object *object_resolve_partial_path(Object *parent,
     QTAILQ_FOREACH(prop, &parent->properties, node) {
         Object *found;
 
-        if (!strstart(prop->type, "child<", NULL)) {
+        if (!object_property_is_child(prop)) {
             continue;
         }
 
-- 
1.7.7

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH qom-next] qom: Introduce object_property_is_{child, link}()
  2012-05-26 23:19 [Qemu-devel] [PATCH qom-next] qom: Introduce object_property_is_{child, link}() Andreas Färber
@ 2012-05-28  6:47 ` Paolo Bonzini
  2012-05-28 14:01   ` Andreas Färber
  0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2012-05-28  6:47 UTC (permalink / raw)
  To: Andreas Färber; +Cc: Alexander Barabash, qemu-devel, Anthony Liguori

Il 27/05/2012 01:19, Andreas Färber ha scritto:
> Avoids hardcoding partial string comparisons.
> 
> Signed-off-by: Alexander Barabash <alexander_barabash@mentor.com>
> Signed-off-by: Andreas Färber <afaerber@suse.de>
> ---
>  qom/object.c |   22 ++++++++++++++++------
>  1 files changed, 16 insertions(+), 6 deletions(-)
> 
> diff --git a/qom/object.c b/qom/object.c
> index 173835b..00bb3b0 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -305,6 +305,16 @@ void object_initialize(void *data, const char *typename)
>      object_initialize_with_type(data, type);
>  }
>  
> +static inline bool object_property_is_child(ObjectProperty *prop)
> +{
> +    return strstart(prop->type, "child<", NULL);
> +}
> +
> +static inline bool object_property_is_link(ObjectProperty *prop)
> +{
> +    return strstart(prop->type, "link<", NULL);
> +}
> +
>  static void object_property_del_all(Object *obj)
>  {
>      while (!QTAILQ_EMPTY(&obj->properties)) {
> @@ -327,7 +337,7 @@ static void object_property_del_child(Object *obj, Object *child, Error **errp)
>      ObjectProperty *prop;
>  
>      QTAILQ_FOREACH(prop, &obj->properties, node) {
> -        if (strstart(prop->type, "child<", NULL) && prop->opaque == child) {
> +        if (object_property_is_child(prop) && prop->opaque == child) {
>              object_property_del(obj, prop->name, errp);
>              break;
>          }
> @@ -600,7 +610,7 @@ int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque),
>      int ret = 0;
>  
>      QTAILQ_FOREACH(prop, &obj->properties, node) {
> -        if (strstart(prop->type, "child<", NULL)) {
> +        if (object_property_is_child(prop)) {
>              ret = fn(prop->opaque, opaque);
>              if (ret != 0) {
>                  break;
> @@ -1022,7 +1032,7 @@ gchar *object_get_canonical_path(Object *obj)
>          g_assert(obj->parent != NULL);
>  
>          QTAILQ_FOREACH(prop, &obj->parent->properties, node) {
> -            if (!strstart(prop->type, "child<", NULL)) {
> +            if (!object_property_is_child(prop)) {
>                  continue;
>              }
>  
> @@ -1056,9 +1066,9 @@ Object *object_resolve_path_component(Object *parent, gchar *part)
>          return NULL;
>      }
>  
> -    if (strstart(prop->type, "link<", NULL)) {
> +    if (object_property_is_link(prop)) {
>          return *(Object **)prop->opaque;
> -    } else if (strstart(prop->type, "child<", NULL)) {
> +    } else if (object_property_is_child(prop)) {
>          return prop->opaque;
>      } else {
>          return NULL;
> @@ -1101,7 +1111,7 @@ static Object *object_resolve_partial_path(Object *parent,
>      QTAILQ_FOREACH(prop, &parent->properties, node) {
>          Object *found;
>  
> -        if (!strstart(prop->type, "child<", NULL)) {
> +        if (!object_property_is_child(prop)) {
>              continue;
>          }
>  

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

Paolo

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH qom-next] qom: Introduce object_property_is_{child, link}()
  2012-05-28  6:47 ` Paolo Bonzini
@ 2012-05-28 14:01   ` Andreas Färber
  0 siblings, 0 replies; 3+ messages in thread
From: Andreas Färber @ 2012-05-28 14:01 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Anthony Liguori, qemu-devel, Alexander Barabash

Am 28.05.2012 08:47, schrieb Paolo Bonzini:
> Il 27/05/2012 01:19, Andreas Färber ha scritto:
>> Avoids hardcoding partial string comparisons.
>>
>> Signed-off-by: Alexander Barabash <alexander_barabash@mentor.com>
>> Signed-off-by: Andreas Färber <afaerber@suse.de>
[...]
> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

Thanks, applied to qom-next:
http://repo.or.cz/w/qemu/afaerber.git/shortlog/refs/heads/qom-next

/-F

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-05-28 14:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-26 23:19 [Qemu-devel] [PATCH qom-next] qom: Introduce object_property_is_{child, link}() Andreas Färber
2012-05-28  6:47 ` Paolo Bonzini
2012-05-28 14:01   ` Andreas Färber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).