]> xenbits.xensource.com Git - libvirt.git/commitdiff
cpu_x86: Use array of vendors in CPU map
authorJiri Denemark <jdenemar@redhat.com>
Tue, 17 May 2016 12:30:18 +0000 (14:30 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Fri, 20 May 2016 07:18:56 +0000 (09:18 +0200)
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>
src/cpu/cpu_x86.c

index 5e4fa28ae2ffa23a39b80f37e3ed7e3d05d6c313..ca0e9b712d9625b002fb1ad75304eac2ad27fe3b 100644 (file)
@@ -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;