From: Lennart Poettering Date: Fri, 30 Nov 2018 15:55:33 +0000 (+0100) Subject: conf-files: improve algorithm O(n²) → O(n) X-Git-Tag: v240~163^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=243dd6ae1dad5165de95e960ef7c52ea5acef5e1;p=thirdparty%2Fsystemd.git conf-files: improve algorithm O(n²) → O(n) --- diff --git a/src/basic/conf-files.c b/src/basic/conf-files.c index 7b44ae277d7..6320674fb5b 100644 --- a/src/basic/conf-files.c +++ b/src/basic/conf-files.c @@ -189,11 +189,12 @@ int conf_files_insert(char ***strv, const char *root, char **dirs, const char *p * - do nothing if our new entry matches the existing entry, * - replace the existing entry if our new entry has higher priority. */ - size_t i; + size_t i, n; char *t; int r; - for (i = 0; i < strv_length(*strv); i++) { + n = strv_length(*strv); + for (i = 0; i < n; i++) { int c; c = base_cmp((char* const*) *strv + i, (char* const*) &path);