[PATCH] qom: remove index from object_resolve_abs_path()

Masahiro Yamada posted 1 patch 3 years, 12 months 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/20200510013235.954906-1-masahiroy@kernel.org
Maintainers: "Daniel P. Berrangé" <berrange@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Eduardo Habkost <ehabkost@redhat.com>
qom/object.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
[PATCH] qom: remove index from object_resolve_abs_path()
Posted by Masahiro Yamada 3 years, 12 months ago
You can advance 'parts' to track the current path fragment.
The 'index' parameter is unneeded.

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

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

diff --git a/qom/object.c b/qom/object.c
index aa8a3f24e6..a3ee968b12 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -2012,25 +2012,24 @@ Object *object_resolve_path_component(Object *parent, const gchar *part)
 
 static Object *object_resolve_abs_path(Object *parent,
                                           gchar **parts,
-                                          const char *typename,
-                                          int index)
+                                          const char *typename)
 {
     Object *child;
 
-    if (parts[index] == NULL) {
+    if (*parts == NULL) {
         return object_dynamic_cast(parent, typename);
     }
 
-    if (strcmp(parts[index], "") == 0) {
-        return object_resolve_abs_path(parent, parts, typename, index + 1);
+    if (strcmp(*parts, "") == 0) {
+        return object_resolve_abs_path(parent, parts + 1, typename);
     }
 
-    child = object_resolve_path_component(parent, parts[index]);
+    child = object_resolve_path_component(parent, *parts);
     if (!child) {
         return NULL;
     }
 
-    return object_resolve_abs_path(child, parts, typename, index + 1);
+    return object_resolve_abs_path(child, parts + 1, typename);
 }
 
 static Object *object_resolve_partial_path(Object *parent,
@@ -2042,7 +2041,7 @@ static Object *object_resolve_partial_path(Object *parent,
     GHashTableIter iter;
     ObjectProperty *prop;
 
-    obj = object_resolve_abs_path(parent, parts, typename, 0);
+    obj = object_resolve_abs_path(parent, parts, typename);
 
     g_hash_table_iter_init(&iter, parent->properties);
     while (g_hash_table_iter_next(&iter, NULL, (gpointer *)&prop)) {
@@ -2087,7 +2086,7 @@ Object *object_resolve_path_type(const char *path, const char *typename,
             *ambiguousp = ambiguous;
         }
     } else {
-        obj = object_resolve_abs_path(object_get_root(), parts, typename, 1);
+        obj = object_resolve_abs_path(object_get_root(), parts + 1, typename);
     }
 
     g_strfreev(parts);
-- 
2.25.1


Re: [PATCH] qom: remove index from object_resolve_abs_path()
Posted by Paolo Bonzini 3 years, 11 months ago
On 10/05/20 03:32, Masahiro Yamada wrote:
> You can advance 'parts' to track the current path fragment.
> The 'index' parameter is unneeded.
> 
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
> 
>  qom/object.c | 17 ++++++++---------
>  1 file changed, 8 insertions(+), 9 deletions(-)
> 
> diff --git a/qom/object.c b/qom/object.c
> index aa8a3f24e6..a3ee968b12 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -2012,25 +2012,24 @@ Object *object_resolve_path_component(Object *parent, const gchar *part)
>  
>  static Object *object_resolve_abs_path(Object *parent,
>                                            gchar **parts,
> -                                          const char *typename,
> -                                          int index)
> +                                          const char *typename)
>  {
>      Object *child;
>  
> -    if (parts[index] == NULL) {
> +    if (*parts == NULL) {
>          return object_dynamic_cast(parent, typename);
>      }
>  
> -    if (strcmp(parts[index], "") == 0) {
> -        return object_resolve_abs_path(parent, parts, typename, index + 1);
> +    if (strcmp(*parts, "") == 0) {
> +        return object_resolve_abs_path(parent, parts + 1, typename);
>      }
>  
> -    child = object_resolve_path_component(parent, parts[index]);
> +    child = object_resolve_path_component(parent, *parts);
>      if (!child) {
>          return NULL;
>      }
>  
> -    return object_resolve_abs_path(child, parts, typename, index + 1);
> +    return object_resolve_abs_path(child, parts + 1, typename);
>  }
>  
>  static Object *object_resolve_partial_path(Object *parent,
> @@ -2042,7 +2041,7 @@ static Object *object_resolve_partial_path(Object *parent,
>      GHashTableIter iter;
>      ObjectProperty *prop;
>  
> -    obj = object_resolve_abs_path(parent, parts, typename, 0);
> +    obj = object_resolve_abs_path(parent, parts, typename);
>  
>      g_hash_table_iter_init(&iter, parent->properties);
>      while (g_hash_table_iter_next(&iter, NULL, (gpointer *)&prop)) {
> @@ -2087,7 +2086,7 @@ Object *object_resolve_path_type(const char *path, const char *typename,
>              *ambiguousp = ambiguous;
>          }
>      } else {
> -        obj = object_resolve_abs_path(object_get_root(), parts, typename, 1);
> +        obj = object_resolve_abs_path(object_get_root(), parts + 1, typename);
>      }
>  
>      g_strfreev(parts);
> 

Queued, thanks.

Paolo