virResctrlInfoGetMonitorPrefix: Don't use 'virStringListAdd' to construct list

Pre-allocate a buffer for the upper limit and shrink it afterwards to
avoid use of 'virStringListAdd' in a loop.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2021-02-05 15:28:46 +01:00
parent fb51b85ea2
commit 34088ea47f

View File

@ -1009,15 +1009,15 @@ virResctrlInfoGetMonitorPrefix(virResctrlInfoPtr resctrl,
mon->cache_level = mongrp_info->cache_level;
}
mon->features = g_new0(char *, mongrp_info->nfeatures + 1);
for (i = 0; i < mongrp_info->nfeatures; i++) {
if (STRPREFIX(mongrp_info->features[i], prefix)) {
if (virStringListAdd(&mon->features,
mongrp_info->features[i]) < 0)
goto cleanup;
mon->nfeatures++;
}
if (STRPREFIX(mongrp_info->features[i], prefix))
mon->features[mon->nfeatures++] = g_strdup(mongrp_info->features[i]);
}
mon->features = g_renew(char *, mon->features, mon->nfeatures + 1);
ret = 0;
/* In case *monitor is pointed to some monitor, clean it. */