]> git.ipfire.org Git - thirdparty/libvirt.git/commit
virJSONValueCopy: Don't use virJSONValue(Object|Array)Append
authorPeter Krempa <pkrempa@redhat.com>
Fri, 12 Feb 2021 09:44:49 +0000 (10:44 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Sat, 20 Feb 2021 12:26:37 +0000 (13:26 +0100)
commit3e411cbc5f0efc9f7f294b9ae127f399f44cbe04
tree3dcead1f9a02d8ecdb8e235e4f0920c2de342c6c
parentb116e715a8e43469cd1a8979d8c5785f9c298d40
virJSONValueCopy: Don't use virJSONValue(Object|Array)Append

We know the exact number of keys or array members for the copied objects
so we can pre-allocate the arrays rather than inserting into them in a
loop incurring realloc copy penalty.

Also virJSONValueCopy now can't fail since all of the functions
allocating the different cases use just g_new/g_strdup internally so we
can remove the NULL checks from the recursive calls.

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