From 22137d3952ad3374a9e2f7182e538853e9403281 Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Tue, 17 May 2016 14:30:18 +0200 Subject: [PATCH] cpu_x86: 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 --- src/cpu/cpu_x86.c | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 5e4fa28ae2..ca0e9b712d 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -49,8 +49,6 @@ typedef virCPUx86Vendor *virCPUx86VendorPtr; struct _virCPUx86Vendor { char *name; virCPUx86CPUID cpuid; - - virCPUx86VendorPtr next; }; typedef struct _virCPUx86Feature virCPUx86Feature; @@ -102,7 +100,8 @@ struct _virCPUx86Model { typedef struct _virCPUx86Map virCPUx86Map; typedef virCPUx86Map *virCPUx86MapPtr; struct _virCPUx86Map { - virCPUx86VendorPtr vendors; + size_t nvendors; + virCPUx86VendorPtr *vendors; virCPUx86FeaturePtr features; size_t nmodels; virCPUx86ModelPtr *models; @@ -433,16 +432,16 @@ static virCPUx86VendorPtr x86DataToVendor(const virCPUx86Data *data, virCPUx86MapPtr map) { - virCPUx86VendorPtr vendor = map->vendors; virCPUx86CPUID *cpuid; + size_t i; - while (vendor) { + for (i = 0; i < map->nvendors; i++) { + virCPUx86VendorPtr vendor = map->vendors[i]; if ((cpuid = x86DataCpuid(data, vendor->cpuid.function)) && x86cpuidMatchMasked(cpuid, &vendor->cpuid)) { x86cpuidClearBits(cpuid, &vendor->cpuid); return vendor; } - vendor = vendor->next; } return NULL; @@ -506,14 +505,11 @@ static virCPUx86VendorPtr x86VendorFind(virCPUx86MapPtr map, const char *name) { - virCPUx86VendorPtr vendor; - - vendor = map->vendors; - while (vendor) { - if (STREQ(vendor->name, name)) - return vendor; + size_t i; - vendor = vendor->next; + for (i = 0; i < map->nvendors; i++) { + if (STREQ(map->vendors[i]->name, name)) + return map->vendors[i]; } return NULL; @@ -562,9 +558,8 @@ x86VendorLoad(xmlXPathContextPtr ctxt, vendor->cpuid.edx = virReadBufInt32LE(string + 4); vendor->cpuid.ecx = virReadBufInt32LE(string + 8); - vendor->next = map->vendors; - map->vendors = vendor; - vendor = NULL; + if (VIR_APPEND_ELEMENT(map->vendors, map->nvendors, vendor) < 0) + goto cleanup; ret = 0; @@ -1121,11 +1116,9 @@ x86MapFree(virCPUx86MapPtr map) x86ModelFree(map->models[i]); VIR_FREE(map->models); - while (map->vendors) { - virCPUx86VendorPtr vendor = map->vendors; - map->vendors = vendor->next; - x86VendorFree(vendor); - } + for (i = 0; i < map->nvendors; i++) + x86VendorFree(map->vendors[i]); + VIR_FREE(map->vendors); while (map->migrate_blockers) { virCPUx86FeaturePtr migrate_blocker = map->migrate_blockers; -- GitLab