]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Remove pointless storage of var names in virNWFilterHashTable
authorDaniel P. Berrange <berrange@redhat.com>
Mon, 24 Mar 2014 16:35:23 +0000 (16:35 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Fri, 25 Apr 2014 14:44:09 +0000 (15:44 +0100)
The virNWFilterHashTable struct contains a virHashTable and
then a 'char **names' field which keeps a copy of all the
hash keys. Presumably this was intended to record the ordering
of the hash keys. No code ever uses this and the ordering is
mangled whenever a variable is removed from the hash, because
the last element in the list is copied into the middle of the
list when shrinking the array.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
src/conf/nwfilter_ipaddrmap.c
src/conf/nwfilter_params.c
src/conf/nwfilter_params.h
src/nwfilter/nwfilter_gentech_driver.c

index 4bb6775e2c926e02e882963cefc377aa28c59d32..446f3de4f903c8b2a0fc7663fd4a8bd3ee596f91 100644 (file)
@@ -60,7 +60,7 @@ virNWFilterIPAddrMapAddIPAddr(const char *ifname, char *addr)
         val = virNWFilterVarValueCreateSimple(addr);
         if (!val)
             goto cleanup;
-        ret = virNWFilterHashTablePut(ipAddressMap, ifname, val, 1);
+        ret = virNWFilterHashTablePut(ipAddressMap, ifname, val);
         goto cleanup;
     } else {
         if (virNWFilterVarValueAddValue(val, addr) < 0)
index 3e85bc1623b753d2af17c46133ebc415adfda93a..765503336236aa35dc7babc25e9cf61cdcc76d50 100644 (file)
@@ -631,33 +631,14 @@ hashDataFree(void *payload, const void *name ATTRIBUTE_UNUSED)
 int
 virNWFilterHashTablePut(virNWFilterHashTablePtr table,
                         const char *name,
-                        virNWFilterVarValuePtr val,
-                        int copyName)
+                        virNWFilterVarValuePtr val)
 {
     if (!virHashLookup(table->hashTable, name)) {
-        char *newName;
-        if (copyName) {
-            if (VIR_STRDUP(newName, name) < 0)
-                return -1;
-
-            if (VIR_APPEND_ELEMENT_COPY(table->names,
-                                        table->nNames, newName) < 0) {
-                VIR_FREE(newName);
-                return -1;
-            }
-        }
-
-        if (virHashAddEntry(table->hashTable, name, val) < 0) {
-            if (copyName) {
-                VIR_FREE(newName);
-                table->nNames--;
-            }
+        if (virHashAddEntry(table->hashTable, name, val) < 0)
             return -1;
-        }
     } else {
-        if (virHashUpdateEntry(table->hashTable, name, val) < 0) {
+        if (virHashUpdateEntry(table->hashTable, name, val) < 0)
             return -1;
-        }
     }
     return 0;
 }
@@ -675,14 +656,10 @@ virNWFilterHashTablePut(virNWFilterHashTablePtr table,
 void
 virNWFilterHashTableFree(virNWFilterHashTablePtr table)
 {
-    size_t i;
     if (!table)
         return;
     virHashFree(table->hashTable);
 
-    for (i = 0; i < table->nNames; i++)
-        VIR_FREE(table->names[i]);
-    VIR_FREE(table->names);
     VIR_FREE(table);
 }
 
@@ -707,20 +684,7 @@ void *
 virNWFilterHashTableRemoveEntry(virNWFilterHashTablePtr ht,
                                 const char *entry)
 {
-    size_t i;
-    void *value = virHashSteal(ht->hashTable, entry);
-
-    if (value) {
-        for (i = 0; i < ht->nNames; i++) {
-            if (STREQ(ht->names[i], entry)) {
-                VIR_FREE(ht->names[i]);
-                ht->names[i] = ht->names[--ht->nNames];
-                ht->names[ht->nNames] = NULL;
-                break;
-            }
-        }
-    }
-    return value;
+    return virHashSteal(ht->hashTable, entry);
 }
 
 
@@ -745,7 +709,7 @@ addToTable(void *payload, const void *name, void *data)
         return;
     }
 
-    if (virNWFilterHashTablePut(atts->target, (const char *)name, val, 1) < 0){
+    if (virNWFilterHashTablePut(atts->target, (const char *)name, val) < 0){
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Could not put variable '%s' into hashmap"),
                        (const char *)name);
@@ -850,7 +814,7 @@ virNWFilterParseParamAttributes(xmlNodePtr cur)
                         value = virNWFilterParseVarValue(val);
                         if (!value)
                             goto skip_entry;
-                        if (virNWFilterHashTablePut(table, nam, value, 1) < 0)
+                        if (virNWFilterHashTablePut(table, nam, value) < 0)
                             goto err_exit;
                     }
                     value = NULL;
index 5e9777b61e5bd543c65ab7ff1a7e94146579843d..f9efc42f9eaba263fd7f97cca3c1686560059530 100644 (file)
@@ -66,9 +66,6 @@ typedef struct _virNWFilterHashTable virNWFilterHashTable;
 typedef virNWFilterHashTable *virNWFilterHashTablePtr;
 struct _virNWFilterHashTable {
     virHashTablePtr hashTable;
-
-    size_t nNames;
-    char **names;
 };
 
 
@@ -81,8 +78,7 @@ virNWFilterHashTablePtr virNWFilterHashTableCreate(int n);
 void virNWFilterHashTableFree(virNWFilterHashTablePtr table);
 int virNWFilterHashTablePut(virNWFilterHashTablePtr table,
                             const char *name,
-                            virNWFilterVarValuePtr val,
-                            int freeName);
+                            virNWFilterVarValuePtr val);
 void *virNWFilterHashTableRemoveEntry(virNWFilterHashTablePtr table,
                                       const char *name);
 int virNWFilterHashTablePutAll(virNWFilterHashTablePtr src,
index 82ff62874ae50160a4dad22fc547059547b4319b..d482f43347a955dfd609a5ec3f6a1b9145ef3f88 100644 (file)
@@ -512,7 +512,7 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter,
 
                     varAccess = virBufferContentAndReset(&buf);
                     virNWFilterHashTablePut(missing_vars, varAccess,
-                                            val, 1);
+                                            val);
                     VIR_FREE(varAccess);
                 }
             }