summaryrefslogtreecommitdiff
path: root/libnm-core/nm-keyfile-utils.c
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-04-13 14:54:23 +0200
committerThomas Haller <thaller@redhat.com>2018-04-19 09:36:41 +0200
commit584a06e4e8e001c23c6590553bc01e313699ac39 (patch)
tree9d2e9c716fdaa2531fdb25eeef59c80d6a23b174 /libnm-core/nm-keyfile-utils.c
parent8d93017b1659ba950a2e33e9a103ebfaaa6809b4 (diff)
downloadNetworkManager-584a06e4e8e001c23c6590553bc01e313699ac39.tar.gz
keyfile: optimize parsing of addresses/routes in keyfile reader
With this, parsing the properties address/route (for both IPv4/IPv6) has a runtime complexity of O(n*ln(n)). Previously, parsing these properties was O(1), but the constant factor was very high because for each address/route x ipv4/ipv6 combination we would search about 2*1001 times whether there is a matching value. Now the runtime complexity is O(n*ln(n)) for each of these 4 properties where n is the number of entries in the keyfile. Also note, that we only have 4 properties for which the parsing has this complexity. Hence, parsing the entire keyfile is still O(n) + 4*O(n*ln(n)) which reduces to O(n*ln(n)). So, parsing the entire keyfile is still benign and the logarithmic factor comes merely from sorting (which is fast). Now, the number of supported addresses/routes is no longer limited to 1000 (as before). Now we would accept all keys up from 0 up to G_MAXINT32. Like before, indexes will be automatically adjusted and gaps in the numbering are accepted. That is convenient, if the user edits the keyfile manually and deletes some lines. And we anyway must not change behavior. $ multitime -n 200 -s 0 -q ./src/settings/plugins/keyfile/tests/test-keyfile # build with -O2 --without-more-asserts # before: Mean Std.Dev. Min Median Max real 0.290+/-0.0000 0.013 0.275 0.289 0.418 user 0.284+/-0.0000 0.010 0.267 0.284 0.331 # after: Mean Std.Dev. Min Median Max real 0.101+/-0.0000 0.002 0.099 0.100 0.118 user 0.096+/-0.0000 0.003 0.091 0.096 0.113 sys 0.004+/-0.0000 0.002 0.001 0.004 0.009
Diffstat (limited to 'libnm-core/nm-keyfile-utils.c')
-rw-r--r--libnm-core/nm-keyfile-utils.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/libnm-core/nm-keyfile-utils.c b/libnm-core/nm-keyfile-utils.c
index 8858331949..dc24a5e9f7 100644
--- a/libnm-core/nm-keyfile-utils.c
+++ b/libnm-core/nm-keyfile-utils.c
@@ -195,7 +195,7 @@ nm_keyfile_plugin_kf_get_keys (GKeyFile *kf,
alias = nm_keyfile_plugin_get_alias_for_setting_name (group);
if (alias) {
g_clear_error (&local);
- keys = g_key_file_get_keys (kf, alias, out_length, &local);
+ keys = g_key_file_get_keys (kf, alias, out_length, error ? &local : NULL);
}
}
if (local)