1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

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: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Jiri Denemark 2016-05-17 15:56:53 +02:00
parent 3a7cd180a5
commit 1bf79d9041

View File

@ -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 {
}; };
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 *
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; for (i = 0; i < map->nvendors; i++) {
while (vendor) { if (STREQ(map->vendors[i]->name, name))
if (STREQ(vendor->name, name)) return map->vendors[i];
return vendor;
vendor = vendor->next;
} }
return NULL; return NULL;
@ -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)
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,
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;