提交 1bf79d90 编写于 作者: J Jiri Denemark

cpu_ppc64: Use array of vendors in CPU map

There's no reason for keeping the vendors in a linked list. Especially
when we know upfront the total number of models we are loading.
Signed-off-by: NJiri Denemark <jdenemar@redhat.com>
上级 3a7cd180
...@@ -42,7 +42,6 @@ static const virArch archs[] = { VIR_ARCH_PPC64, VIR_ARCH_PPC64LE }; ...@@ -42,7 +42,6 @@ static const virArch archs[] = { VIR_ARCH_PPC64, VIR_ARCH_PPC64LE };
struct ppc64_vendor { struct ppc64_vendor {
char *name; char *name;
struct ppc64_vendor *next;
}; };
struct ppc64_model { struct ppc64_model {
...@@ -53,7 +52,8 @@ struct ppc64_model { ...@@ -53,7 +52,8 @@ struct ppc64_model {
}; };
struct ppc64_map { struct ppc64_map {
struct ppc64_vendor *vendors; size_t nvendors;
struct ppc64_vendor **vendors;
struct ppc64_model *models; struct ppc64_model *models;
}; };
...@@ -182,14 +182,11 @@ static struct ppc64_vendor * ...@@ -182,14 +182,11 @@ static struct ppc64_vendor *
ppc64VendorFind(const struct ppc64_map *map, ppc64VendorFind(const struct ppc64_map *map,
const char *name) const char *name)
{ {
struct ppc64_vendor *vendor; size_t i;
vendor = map->vendors;
while (vendor) {
if (STREQ(vendor->name, name))
return vendor;
vendor = vendor->next; for (i = 0; i < map->nvendors; i++) {
if (STREQ(map->vendors[i]->name, name))
return map->vendors[i];
} }
return NULL; return NULL;
...@@ -283,6 +280,8 @@ ppc64ModelFromCPU(const virCPUDef *cpu, ...@@ -283,6 +280,8 @@ ppc64ModelFromCPU(const virCPUDef *cpu,
static void static void
ppc64MapFree(struct ppc64_map *map) ppc64MapFree(struct ppc64_map *map)
{ {
size_t i;
if (!map) if (!map)
return; return;
...@@ -292,11 +291,9 @@ ppc64MapFree(struct ppc64_map *map) ...@@ -292,11 +291,9 @@ ppc64MapFree(struct ppc64_map *map)
ppc64ModelFree(model); ppc64ModelFree(model);
} }
while (map->vendors) { for (i = 0; i < map->nvendors; i++)
struct ppc64_vendor *vendor = map->vendors; ppc64VendorFree(map->vendors[i]);
map->vendors = vendor->next; VIR_FREE(map->vendors);
ppc64VendorFree(vendor);
}
VIR_FREE(map); VIR_FREE(map);
} }
...@@ -323,12 +320,8 @@ ppc64VendorLoad(xmlXPathContextPtr ctxt, ...@@ -323,12 +320,8 @@ ppc64VendorLoad(xmlXPathContextPtr ctxt,
goto ignore; goto ignore;
} }
if (!map->vendors) { if (VIR_APPEND_ELEMENT(map->vendors, map->nvendors, vendor) < 0)
map->vendors = vendor; goto ignore;
} else {
vendor->next = map->vendors;
map->vendors = vendor;
}
cleanup: cleanup:
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册