From 5d8399befbd11321ed8617d501ed92ab13325d12 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Mon, 12 Jun 2023 12:35:20 +0300 Subject: [PATCH] tty: refactoring of color pairs deallocation. * (tty_color_free_all_tmp): rename to tty_color_free_temp and call g_hash_table_foreach_remove(). * (tty_color_free_all_non_tmp): rename to tty_color_free_all and call g_hash_table_remove_all(). * (tty_color_free_all): remove. * (tty_color_free_condition_cb): rename to tty_color_free_temp_cb and simplify. * (mc_skin_deinit): use changed API. * (edit_free_syntax_rules): likewise. Signed-off-by: Andrew Borodin --- lib/skin/common.c | 3 +-- lib/tty/color.c | 26 +++++++------------------- lib/tty/color.h | 4 ++-- src/editor/syntax.c | 2 +- 4 files changed, 11 insertions(+), 24 deletions(-) diff --git a/lib/skin/common.c b/lib/skin/common.c index db50a4458..1c10759a8 100644 --- a/lib/skin/common.c +++ b/lib/skin/common.c @@ -181,8 +181,7 @@ mc_skin_init (const gchar * skin_override, GError ** mcerror) void mc_skin_deinit (void) { - tty_color_free_all_tmp (); - tty_color_free_all_non_tmp (); + tty_color_free_all (); MC_PTR_FREE (mc_skin__default.name); g_hash_table_destroy (mc_skin__default.colors); diff --git a/lib/tty/color.c b/lib/tty/color.c index 3da8bcc2a..b0d9e2c19 100644 --- a/lib/tty/color.c +++ b/lib/tty/color.c @@ -84,24 +84,12 @@ mc_color__deinit (tty_color_pair_t * color) /* --------------------------------------------------------------------------------------------- */ static gboolean -tty_color_free_condition_cb (gpointer key, gpointer value, gpointer user_data) +tty_color_free_temp_cb (gpointer key, gpointer value, gpointer user_data) { - tty_color_lib_pair_t *mc_color_pair = (tty_color_lib_pair_t *) value; - gboolean is_temp_color; - (void) key; + (void) user_data; - is_temp_color = user_data != NULL; - return (mc_color_pair->is_temp == is_temp_color); -} - -/* --------------------------------------------------------------------------------------------- */ - -static void -tty_color_free_all (gboolean is_temp_color) -{ - g_hash_table_foreach_remove (mc_tty_color__hashtable, tty_color_free_condition_cb, - is_temp_color ? GSIZE_TO_POINTER (1) : NULL); + return ((tty_color_lib_pair_t *) value)->is_temp; } /* --------------------------------------------------------------------------------------------- */ @@ -216,17 +204,17 @@ tty_try_alloc_color_pair (const tty_color_pair_t * color, gboolean is_temp) /* --------------------------------------------------------------------------------------------- */ void -tty_color_free_all_tmp (void) +tty_color_free_temp (void) { - tty_color_free_all (TRUE); + g_hash_table_foreach_remove (mc_tty_color__hashtable, tty_color_free_temp_cb, NULL); } /* --------------------------------------------------------------------------------------------- */ void -tty_color_free_all_non_tmp (void) +tty_color_free_all (void) { - tty_color_free_all (FALSE); + g_hash_table_remove_all (mc_tty_color__hashtable); } /* --------------------------------------------------------------------------------------------- */ diff --git a/lib/tty/color.h b/lib/tty/color.h index bf96f3664..e09516f6e 100644 --- a/lib/tty/color.h +++ b/lib/tty/color.h @@ -43,8 +43,8 @@ void tty_colors_done (void); gboolean tty_use_colors (void); int tty_try_alloc_color_pair (const tty_color_pair_t * color, gboolean is_temp); -void tty_color_free_all_tmp (void); -void tty_color_free_all_non_tmp (void); +void tty_color_free_temp (void); +void tty_color_free_all (void); void tty_setcolor (int color); void tty_lowlevel_setcolor (int color); diff --git a/src/editor/syntax.c b/src/editor/syntax.c index aec8cfdd3..c253e8799 100644 --- a/src/editor/syntax.c +++ b/src/editor/syntax.c @@ -1482,7 +1482,7 @@ edit_free_syntax_rules (WEdit * edit) g_ptr_array_free (edit->rules, TRUE); edit->rules = NULL; g_clear_slist (&edit->syntax_marker, g_free); - tty_color_free_all_tmp (); + tty_color_free_temp (); } /* --------------------------------------------------------------------------------------------- */