]> xenbits.xensource.com Git - libvirt.git/commitdiff
virDomainHostdev{Insert,Delete}: Replace VIR_REALLOC_N by VIR_{APPEND,DELETE}_ELEMENT
authorMatthieu Coudron <mattator@gmail.com>
Thu, 6 Feb 2014 14:29:08 +0000 (15:29 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 6 Feb 2014 16:10:26 +0000 (17:10 +0100)
With this change the code gets shorter and more readable.

Signed-off-by: Matthieu Coudron <mattator@gmail.com>
src/conf/domain_conf.c

index 28e24f9555824a7628a575c5fc72ace23de47b93..7ad2a904eb64a646baa06272325f174f23488d3b 100644 (file)
@@ -9868,10 +9868,8 @@ virDomainChrTargetTypeToString(int deviceType,
 int
 virDomainHostdevInsert(virDomainDefPtr def, virDomainHostdevDefPtr hostdev)
 {
-    if (VIR_REALLOC_N(def->hostdevs, def->nhostdevs + 1) < 0)
-        return -1;
-    def->hostdevs[def->nhostdevs++]  = hostdev;
-    return 0;
+
+    return VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev);
 }
 
 virDomainHostdevDefPtr
@@ -9879,19 +9877,7 @@ virDomainHostdevRemove(virDomainDefPtr def, size_t i)
 {
     virDomainHostdevDefPtr hostdev = def->hostdevs[i];
 
-    if (def->nhostdevs > 1) {
-        memmove(def->hostdevs + i,
-                def->hostdevs + i + 1,
-                sizeof(*def->hostdevs) *
-                (def->nhostdevs - (i + 1)));
-        def->nhostdevs--;
-        if (VIR_REALLOC_N(def->hostdevs, def->nhostdevs) < 0) {
-            /* ignore, harmless */
-        }
-    } else {
-        VIR_FREE(def->hostdevs);
-        def->nhostdevs = 0;
-    }
+    VIR_DELETE_ELEMENT(def->hostdevs, i, def->nhostdevs);
     return hostdev;
 }