]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: json: Replace virJSONValueObjectSteal by virJSONValueObjectRemoveKey
authorPeter Krempa <pkrempa@redhat.com>
Mon, 30 Nov 2020 13:59:38 +0000 (14:59 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 8 Jan 2021 08:17:25 +0000 (09:17 +0100)
virJSONValueObjectRemoveKey can be used as direct replacement. Fix the
one caller and remove the duplicate function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/util/virjson.c

index c80c2f1ecb1e99c27b8778e4237e7c90b9deb195..f85b61957c278abff5c2ad9694bbc72086384b86 100644 (file)
@@ -883,30 +883,6 @@ virJSONValueObjectGet(virJSONValuePtr object,
 }
 
 
-static virJSONValuePtr
-virJSONValueObjectSteal(virJSONValuePtr object,
-                        const char *key)
-{
-    size_t i;
-    virJSONValuePtr obj = NULL;
-
-    if (object->type != VIR_JSON_TYPE_OBJECT)
-        return NULL;
-
-    for (i = 0; i < object->data.object.npairs; i++) {
-        if (STREQ(object->data.object.pairs[i].key, key)) {
-            obj = g_steal_pointer(&object->data.object.pairs[i].value);
-            VIR_FREE(object->data.object.pairs[i].key);
-            VIR_DELETE_ELEMENT(object->data.object.pairs, i,
-                               object->data.object.npairs);
-            break;
-        }
-    }
-
-    return obj;
-}
-
-
 /* Return the value associated with KEY within OBJECT, but return NULL
  * if the key is missing or if value is not the correct TYPE.  */
 virJSONValuePtr
@@ -929,7 +905,10 @@ virJSONValueObjectStealByType(virJSONValuePtr object,
                               const char *key,
                               virJSONType type)
 {
-    virJSONValuePtr value = virJSONValueObjectSteal(object, key);
+    virJSONValuePtr value;
+
+    if (virJSONValueObjectRemoveKey(object, key, &value) <= 0)
+        return NULL;
 
     if (value && value->type == type)
         return value;