mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-13 23:20:34 +01:00
libnm: pre-allocate buffer in _nm_sett_info_property_override_create_array()
The buffer created here is only temporary to construct the property info by _nm_setting_class_commit_full(). We can afford to allocate more than necessary, if we thereby avoid several reallocations.
This commit is contained in:
parent
5995653312
commit
58c3af1a7d
2 changed files with 28 additions and 16 deletions
|
|
@ -278,10 +278,19 @@ gboolean _nm_setting_property_is_regular_secret_flags(NMSetting * setting,
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
static inline GArray *
|
||||
_nm_sett_info_property_override_create_array_sized(guint reserved_size)
|
||||
{
|
||||
return g_array_sized_new(FALSE, FALSE, sizeof(NMSettInfoProperty), reserved_size);
|
||||
}
|
||||
|
||||
static inline GArray *
|
||||
_nm_sett_info_property_override_create_array(void)
|
||||
{
|
||||
return g_array_new(FALSE, FALSE, sizeof(NMSettInfoProperty));
|
||||
/* pre-allocate a relatively large buffer to avoid frequent re-allocations.
|
||||
* Note that the buffer is only short-lived and will be destroyed by
|
||||
* _nm_setting_class_commit_full(). */
|
||||
return _nm_sett_info_property_override_create_array_sized(20);
|
||||
}
|
||||
|
||||
GArray *_nm_sett_info_property_override_create_array_ip_config(void);
|
||||
|
|
|
|||
|
|
@ -296,7 +296,9 @@ _nm_setting_class_commit_full(NMSettingClass * setting_class,
|
|||
{
|
||||
NMSettInfoSetting *sett_info;
|
||||
gs_free GParamSpec **property_specs = NULL;
|
||||
guint i, n_property_specs, override_len;
|
||||
guint n_property_specs;
|
||||
guint override_len;
|
||||
guint i;
|
||||
|
||||
nm_assert(NM_IS_SETTING_CLASS(setting_class));
|
||||
nm_assert(!setting_class->setting_info);
|
||||
|
|
@ -309,25 +311,26 @@ _nm_setting_class_commit_full(NMSettingClass * setting_class,
|
|||
nm_assert(!sett_info->property_infos_len);
|
||||
nm_assert(!sett_info->property_infos);
|
||||
|
||||
if (!properties_override) {
|
||||
override_len = 0;
|
||||
properties_override = _nm_sett_info_property_override_create_array();
|
||||
} else
|
||||
override_len = properties_override->len;
|
||||
|
||||
property_specs =
|
||||
g_object_class_list_properties(G_OBJECT_CLASS(setting_class), &n_property_specs);
|
||||
|
||||
for (i = 0; i < properties_override->len; i++) {
|
||||
NMSettInfoProperty *p = &g_array_index(properties_override, NMSettInfoProperty, i);
|
||||
if (!properties_override) {
|
||||
override_len = 0;
|
||||
properties_override = _nm_sett_info_property_override_create_array_sized(n_property_specs);
|
||||
} else {
|
||||
override_len = properties_override->len;
|
||||
|
||||
nm_assert((!!p->name) != (!!p->param_spec));
|
||||
for (i = 0; i < override_len; i++) {
|
||||
NMSettInfoProperty *p = &g_array_index(properties_override, NMSettInfoProperty, i);
|
||||
|
||||
if (!p->name) {
|
||||
nm_assert(p->param_spec);
|
||||
p->name = p->param_spec->name;
|
||||
} else
|
||||
nm_assert(!p->param_spec);
|
||||
nm_assert((!!p->name) != (!!p->param_spec));
|
||||
|
||||
if (!p->name) {
|
||||
nm_assert(p->param_spec);
|
||||
p->name = p->param_spec->name;
|
||||
} else
|
||||
nm_assert(!p->param_spec);
|
||||
}
|
||||
}
|
||||
|
||||
#if NM_MORE_ASSERTS > 10
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue