mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
qemuInteropFetchConfigs: Don't use 'virStringListAdd' to construct list
'virHashGetItems' already returns the number of entries which will be considered for addition to the list so we can allocate it to the upper bound upfront rather than growing it in a loop. This avoids the quadratic complexity of 'virStringListAdd'. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
97fd333fde
commit
f060d62c75
@ -94,7 +94,9 @@ qemuInteropFetchConfigs(const char *name,
|
|||||||
g_autofree char *sysLocation = virFileBuildPath(QEMU_SYSTEM_LOCATION, name, NULL);
|
g_autofree char *sysLocation = virFileBuildPath(QEMU_SYSTEM_LOCATION, name, NULL);
|
||||||
g_autofree char *etcLocation = virFileBuildPath(QEMU_ETC_LOCATION, name, NULL);
|
g_autofree char *etcLocation = virFileBuildPath(QEMU_ETC_LOCATION, name, NULL);
|
||||||
g_autofree virHashKeyValuePairPtr pairs = NULL;
|
g_autofree virHashKeyValuePairPtr pairs = NULL;
|
||||||
|
size_t npairs;
|
||||||
virHashKeyValuePairPtr tmp = NULL;
|
virHashKeyValuePairPtr tmp = NULL;
|
||||||
|
size_t nconfigs = 0;
|
||||||
|
|
||||||
*configs = NULL;
|
*configs = NULL;
|
||||||
|
|
||||||
@ -132,11 +134,13 @@ qemuInteropFetchConfigs(const char *name,
|
|||||||
* where each filename (as key) has the highest priority full pathname
|
* where each filename (as key) has the highest priority full pathname
|
||||||
* associated with it. */
|
* associated with it. */
|
||||||
|
|
||||||
if (virHashSize(files) == 0)
|
if (!(pairs = virHashGetItems(files, &npairs, true)))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (npairs == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!(pairs = virHashGetItems(files, NULL, true)))
|
*configs = g_new0(char *, npairs + 1);
|
||||||
return -1;
|
|
||||||
|
|
||||||
for (tmp = pairs; tmp->key; tmp++) {
|
for (tmp = pairs; tmp->key; tmp++) {
|
||||||
const char *path = tmp->value;
|
const char *path = tmp->value;
|
||||||
@ -158,8 +162,7 @@ qemuInteropFetchConfigs(const char *name,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virStringListAdd(configs, path) < 0)
|
(*configs)[nconfigs++] = g_strdup(path);
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user