]> xenbits.xensource.com Git - libvirt.git/commitdiff
src/util: Utilize more of VIR_(APPEND|INSERT|DELETE)_ELEMENT
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 7 Mar 2014 08:33:31 +0000 (09:33 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 10 Mar 2014 12:45:11 +0000 (13:45 +0100)
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/util/virjson.c
src/util/virlockspace.c

index 7044e11b989f4ad17b35cf3e195990ca662d315b..02b5f3fa1b938667afeb4aa57628c96038de8e9c 100644 (file)
@@ -58,7 +58,7 @@ typedef virJSONParser *virJSONParserPtr;
 struct _virJSONParser {
     virJSONValuePtr head;
     virJSONParserStatePtr state;
-    unsigned int nstate;
+    size_t nstate;
 };
 
 
@@ -889,10 +889,7 @@ static int virJSONParserHandleEndMap(void *ctx)
         return 0;
     }
 
-    if (VIR_REALLOC_N(parser->state,
-                      parser->nstate - 1) < 0)
-        return 0;
-    parser->nstate--;
+    VIR_DELETE_ELEMENT(parser->state, parser->nstate - 1, parser->nstate);
 
     return 1;
 }
@@ -939,10 +936,7 @@ static int virJSONParserHandleEndArray(void *ctx)
         return 0;
     }
 
-    if (VIR_REALLOC_N(parser->state,
-                      parser->nstate - 1) < 0)
-        return 0;
-    parser->nstate--;
+    VIR_DELETE_ELEMENT(parser->state, parser->nstate - 1, parser->nstate);
 
     return 1;
 }
index cab7775c7a5b231725d72c1ec548ce9beec6272c..90a39bb5435c35959be684c02e89cb7a2753dd38 100644 (file)
@@ -689,11 +689,7 @@ int virLockSpaceReleaseResource(virLockSpacePtr lockspace,
         goto cleanup;
     }
 
-    if (i < (res->nOwners - 1))
-        memmove(res->owners + i,
-                res->owners + i + 1,
-                (res->nOwners - i - 1) * sizeof(res->owners[0]));
-    VIR_SHRINK_N(res->owners, res->nOwners, 1);
+    VIR_DELETE_ELEMENT(res->owners, i, res->nOwners);
 
     if ((res->nOwners == 0) &&
         virHashRemoveEntry(lockspace->resources, resname) < 0)
@@ -735,11 +731,7 @@ virLockSpaceRemoveResourcesForOwner(const void *payload,
 
     data->count++;
 
-    if (i < (res->nOwners - 1))
-        memmove(res->owners + i,
-                res->owners + i + 1,
-                (res->nOwners - i - 1) * sizeof(res->owners[0]));
-    VIR_SHRINK_N(res->owners, res->nOwners, 1);
+    VIR_DELETE_ELEMENT(res->owners, i, res->nOwners);
 
     if (res->nOwners) {
         VIR_DEBUG("Other shared owners remain");