cpu_x86: Refactor feature list comparison in x86DecodeUseCandidate

It will become more complicated and so it deserves to be separated into
a new function.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Jiri Denemark 2022-04-26 15:02:51 +02:00
parent 35ce086667
commit 1d6ca40ac2

View File

@ -1956,6 +1956,27 @@ virCPUx86Compare(virCPUDef *host,
}
static int
virCPUx86CompareCandidateFeatureList(virCPUDef *cpuCurrent,
virCPUDef *cpuCandidate)
{
size_t current = cpuCurrent->nfeatures;
size_t candidate = cpuCandidate->nfeatures;
if (candidate < current) {
VIR_DEBUG("%s is better than %s: %zu < %zu",
cpuCandidate->model, cpuCurrent->model,
candidate, current);
return 1;
}
VIR_DEBUG("%s is not better than %s: %zu >= %zu",
cpuCandidate->model, cpuCurrent->model,
candidate, current);
return 0;
}
/*
* Checks whether a candidate model is a better fit for the CPU data than the
* current model.
@ -2024,15 +2045,7 @@ x86DecodeUseCandidate(virCPUx86Model *current,
}
}
if (cpuCurrent->nfeatures > cpuCandidate->nfeatures) {
VIR_DEBUG("%s results in shorter feature list than %s",
cpuCandidate->model, cpuCurrent->model);
return 1;
}
VIR_DEBUG("%s does not result in shorter feature list than %s",
cpuCandidate->model, cpuCurrent->model);
return 0;
return virCPUx86CompareCandidateFeatureList(cpuCurrent, cpuCandidate);
}