From 495c7304878bdd010dc5d25620dc68f41ac4cd36 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 17 Jun 2021 18:15:29 +0200 Subject: config: don’t use tllist where it isn’t necessary MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tllists are great when dealing with dynamically changing lists. They are also very easy to use when building lists/arrays where the final size is unknown. However, this ease of use comes at a price: code size. tll-macros expand to a lot of code. Since things in the config are static, once the config has been loaded, using tllists for configuration data structures doesn’t make much sense. This patch replaces nearly all tllists used by the configuration, with dynamically allocated arrays. --- main.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 52ebaca6..df9edfd6 100644 --- a/main.c +++ b/main.c @@ -441,17 +441,22 @@ main(int argc, char *const *argv) if (login_shell) conf.login_shell = true; if (tll_length(conf_fonts) > 0) { - for (size_t i = 0; i < ALEN(conf.fonts); i++) { - tll_foreach(conf.fonts[i], it) - config_font_destroy(&it->item); - tll_free(conf.fonts[i]); - } + for (size_t i = 0; i < ALEN(conf.fonts); i++) + config_font_list_destroy(&conf.fonts[i]); + + struct config_font_list *font_list = &conf.fonts[0]; + xassert(font_list->count == 0); + xassert(font_list->arr == NULL); + + font_list->arr = xmalloc( + tll_length(conf_fonts) * sizeof(font_list->arr[0])); + tll_foreach(conf_fonts, it) { struct config_font font; if (!config_font_parse(it->item, &font)) { LOG_ERR("%s: invalid font specification", it->item); } else - tll_push_back(conf.fonts[0], font); + font_list->arr[font_list->count++] = font; } tll_free(conf_fonts); } -- cgit v1.3