mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
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:
parent
fb51b85ea2
commit
34088ea47f
@ -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. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user