提交 77646d94 编写于 作者: D Daniel P. Berrangé

nwfilter: remove pointless virNWFilterHashTable struct

The virNWFilterHashTable struct only contains a single virHashTable
member since

  commit 293d4fe2
  Author: Daniel P. Berrange <berrange@redhat.com>
  Date:   Mon Mar 24 16:35:23 2014 +0000

    Remove pointless storage of var names in virNWFilterHashTable

Thus, this struct wrapper adds no real value over just using the
virHashTable directly, but brings the complexity of needing to derefence
the hashtable to call virHash* APIs, and adds extra memory allocation
step.

To minimize code churn this just turns virNWFilterHashTable into a
typedef aliases virHashTable.
Reviewed-by: NJiri Denemark <jdenemar@redhat.com>
Signed-off-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 81cb05b7
......@@ -61,7 +61,7 @@ virNWFilterIPAddrMapAddIPAddr(const char *ifname, char *addr)
virMutexLock(&ipAddressMapLock);
val = virHashLookup(ipAddressMap->hashTable, ifname);
val = virHashLookup(ipAddressMap, ifname);
if (!val) {
val = virNWFilterVarValueCreateSimple(addrCopy);
if (!val)
......@@ -109,7 +109,7 @@ virNWFilterIPAddrMapDelIPAddr(const char *ifname, const char *ipaddr)
virMutexLock(&ipAddressMapLock);
if (ipaddr != NULL) {
val = virHashLookup(ipAddressMap->hashTable, ifname);
val = virHashLookup(ipAddressMap, ifname);
if (val) {
if (virNWFilterVarValueGetCardinality(val) == 1 &&
STREQ(ipaddr,
......@@ -144,7 +144,7 @@ virNWFilterIPAddrMapGetIPAddr(const char *ifname)
virMutexLock(&ipAddressMapLock);
res = virHashLookup(ipAddressMap->hashTable, ifname);
res = virHashLookup(ipAddressMap, ifname);
virMutexUnlock(&ipAddressMapLock);
......
......@@ -355,7 +355,7 @@ virNWFilterVarCombIterAddVariable(virNWFilterVarCombIterEntryPtr cie,
unsigned int maxValue = 0, minValue = 0;
const char *varName = virNWFilterVarAccessGetVarName(varAccess);
varValue = virHashLookup(hash->hashTable, varName);
varValue = virHashLookup(hash, varName);
if (varValue == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not find value for variable '%s'"),
......@@ -421,7 +421,7 @@ virNWFilterVarCombIterEntryAreUniqueEntries(virNWFilterVarCombIterEntryPtr cie,
virNWFilterVarValuePtr varValue, tmp;
const char *value;
varValue = virHashLookup(hash->hashTable, cie->varNames[0]);
varValue = virHashLookup(hash, cie->varNames[0]);
if (!varValue) {
/* caller's error */
VIR_ERROR(_("hash lookup resulted in NULL pointer"));
......@@ -439,7 +439,7 @@ virNWFilterVarCombIterEntryAreUniqueEntries(virNWFilterVarCombIterEntryPtr cie,
if (STREQ(value, virNWFilterVarValueGetNthValue(varValue, i))) {
bool isSame = true;
for (j = 1; j < cie->nVarNames; j++) {
tmp = virHashLookup(hash->hashTable, cie->varNames[j]);
tmp = virHashLookup(hash, cie->varNames[j]);
if (!tmp) {
/* should never occur to step on a NULL here */
return true;
......@@ -604,7 +604,7 @@ virNWFilterVarCombIterGetVarValue(virNWFilterVarCombIterPtr ci,
return NULL;
}
value = virHashLookup(ci->hashTable->hashTable, varName);
value = virHashLookup(ci->hashTable, varName);
if (!value) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not find value for variable '%s'"),
......@@ -648,11 +648,11 @@ virNWFilterHashTablePut(virNWFilterHashTablePtr table,
const char *name,
virNWFilterVarValuePtr val)
{
if (!virHashLookup(table->hashTable, name)) {
if (virHashAddEntry(table->hashTable, name, val) < 0)
if (!virHashLookup(table, name)) {
if (virHashAddEntry(table, name, val) < 0)
return -1;
} else {
if (virHashUpdateEntry(table->hashTable, name, val) < 0)
if (virHashUpdateEntry(table, name, val) < 0)
return -1;
}
return 0;
......@@ -671,27 +671,14 @@ virNWFilterHashTablePut(virNWFilterHashTablePtr table,
void
virNWFilterHashTableFree(virNWFilterHashTablePtr table)
{
if (!table)
return;
virHashFree(table->hashTable);
VIR_FREE(table);
virHashFree(table);
}
virNWFilterHashTablePtr
virNWFilterHashTableCreate(int n)
{
virNWFilterHashTablePtr ret;
if (VIR_ALLOC(ret) < 0)
return NULL;
ret->hashTable = virHashCreate(n, hashDataFree);
if (!ret->hashTable) {
VIR_FREE(ret);
return NULL;
}
return ret;
return virHashCreate(n, hashDataFree);
}
......@@ -699,7 +686,7 @@ void *
virNWFilterHashTableRemoveEntry(virNWFilterHashTablePtr ht,
const char *entry)
{
return virHashSteal(ht->hashTable, entry);
return virHashSteal(ht, entry);
}
......@@ -745,7 +732,7 @@ virNWFilterHashTablePutAll(virNWFilterHashTablePtr src,
.errOccurred = 0,
};
virHashForEach(src->hashTable, addToTable, &atts);
virHashForEach(src, addToTable, &atts);
if (atts.errOccurred)
goto err_exit;
......@@ -770,11 +757,7 @@ bool
virNWFilterHashTableEqual(virNWFilterHashTablePtr a,
virNWFilterHashTablePtr b)
{
if (!(a || b))
return true;
if (!(a && b))
return false;
return virHashEqual(a->hashTable, b->hashTable, virNWFilterVarValueCompare);
return virHashEqual(a, b, virNWFilterVarValueCompare);
}
static bool
......@@ -819,7 +802,7 @@ virNWFilterParseParamAttributes(xmlNodePtr cur)
goto skip_entry;
if (!isValidVarValue(val))
goto skip_entry;
value = virHashLookup(table->hashTable, nam);
value = virHashLookup(table, nam);
if (value) {
/* add value to existing value -> list */
if (virNWFilterVarValueAddValue(value, val) < 0) {
......@@ -871,7 +854,7 @@ virNWFilterFormatParamAttributes(virBufferPtr buf,
size_t i, j;
int card, numKeys;
numKeys = virHashSize(table->hashTable);
numKeys = virHashSize(table);
if (numKeys < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
......@@ -879,7 +862,7 @@ virNWFilterFormatParamAttributes(virBufferPtr buf,
return -1;
}
items = virHashGetItems(table->hashTable,
items = virHashGetItems(table,
virNWFilterFormatParameterNameSorter);
if (!items)
return -1;
......@@ -1103,7 +1086,7 @@ virNWFilterVarAccessIsAvailable(const virNWFilterVarAccess *varAccess,
unsigned int idx;
virNWFilterVarValuePtr varValue;
varValue = virHashLookup(hash->hashTable, varName);
varValue = virHashLookup(hash, varName);
if (!varValue)
return false;
......
......@@ -63,12 +63,8 @@ int virNWFilterVarValueAddValue(virNWFilterVarValuePtr val, char *value);
int virNWFilterVarValueAddValueCopy(virNWFilterVarValuePtr val, const char *value);
int virNWFilterVarValueDelValue(virNWFilterVarValuePtr val, const char *value);
typedef struct _virNWFilterHashTable virNWFilterHashTable;
typedef virNWFilterHashTable *virNWFilterHashTablePtr;
struct _virNWFilterHashTable {
virHashTablePtr hashTable;
};
typedef virHashTable virNWFilterHashTable;
typedef virHashTable *virNWFilterHashTablePtr;
virNWFilterHashTablePtr virNWFilterParseParamAttributes(xmlNodePtr cur);
int virNWFilterFormatParamAttributes(virBufferPtr buf,
......
......@@ -894,7 +894,7 @@ virNWFilterSnoopReqLeaseDel(virNWFilterSnoopReqPtr req,
req->vars);
} else {
virNWFilterVarValuePtr dhcpsrvrs =
virHashLookup(req->vars->hashTable, NWFILTER_VARNAME_DHCPSERVER);
virHashLookup(req->vars, NWFILTER_VARNAME_DHCPSERVER);
if (req->techdriver &&
req->techdriver->applyDHCPOnlyRules(req->ifname, &req->macaddr,
......@@ -1664,7 +1664,7 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver,
goto exit_snoopreqput;
}
dhcpsrvrs = virHashLookup(filterparams->hashTable,
dhcpsrvrs = virHashLookup(filterparams,
NWFILTER_VARNAME_DHCPSERVER);
if (techdriver->applyDHCPOnlyRules(req->ifname, &req->macaddr,
......
......@@ -153,7 +153,7 @@ virNWFilterVarHashmapAddStdValues(virNWFilterHashTablePtr table,
if (!val)
return -1;
if (virHashAddEntry(table->hashTable,
if (virHashAddEntry(table,
NWFILTER_STD_VAR_MAC,
val) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
......@@ -167,7 +167,7 @@ virNWFilterVarHashmapAddStdValues(virNWFilterHashTablePtr table,
if (!val)
return -1;
if (virHashAddEntry(table->hashTable,
if (virHashAddEntry(table,
NWFILTER_STD_VAR_IP,
val) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
......@@ -633,7 +633,7 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid,
if (rc < 0)
goto err_exit;
lv = virHashLookup(vars->hashTable, NWFILTER_VARNAME_CTRL_IP_LEARNING);
lv = virHashLookup(vars, NWFILTER_VARNAME_CTRL_IP_LEARNING);
if (lv)
learning = virNWFilterVarValueGetNthValue(lv, 0);
else
......@@ -642,8 +642,8 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid,
if (learning == NULL)
learning = NWFILTER_DFLT_LEARN;
if (virHashSize(missing_vars->hashTable) == 1) {
if (virHashLookup(missing_vars->hashTable,
if (virHashSize(missing_vars) == 1) {
if (virHashLookup(missing_vars,
NWFILTER_STD_VAR_IP) != NULL) {
if (STRCASEEQ(learning, "none")) { /* no learning */
reportIP = true;
......@@ -677,7 +677,7 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid,
} else {
goto err_unresolvable_vars;
}
} else if (virHashSize(missing_vars->hashTable) > 1) {
} else if (virHashSize(missing_vars) > 1) {
goto err_unresolvable_vars;
} else if (!forceWithPendingReq &&
virNWFilterLookupLearnReq(ifindex) != NULL) {
......@@ -729,7 +729,7 @@ virNWFilterDoInstantiate(const unsigned char *vmuuid,
err_unresolvable_vars:
buf = virNWFilterPrintVars(missing_vars->hashTable, ", ", false, reportIP);
buf = virNWFilterPrintVars(missing_vars, ", ", false, reportIP);
if (buf) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Cannot instantiate filter due to unresolvable "
......
......@@ -333,7 +333,7 @@ static int testSetOneParameter(virNWFilterHashTablePtr vars,
int ret = -1;
virNWFilterVarValuePtr val;
if ((val = virHashLookup(vars->hashTable, name)) == NULL) {
if ((val = virHashLookup(vars, name)) == NULL) {
val = virNWFilterVarValueCreateSimpleCopyValue(value);
if (!val)
goto cleanup;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册