[glib: 1/4] gio/tests: simplify enum to string in memory-monitor




commit 06160facf39fbdf6b061e8a01f72a4cd3239d7e9
Author: Marc-André Lureau <marcandre lureau redhat com>
Date:   Mon Jan 24 00:54:14 2022 +0400

    gio/tests: simplify enum to string in memory-monitor
    
    Also results in more robust handling, since it can get a NULL eclass.
    
    Signed-off-by: Marc-André Lureau <marcandre lureau redhat com>

 gio/tests/memory-monitor.c | 20 ++------------------
 1 file changed, 2 insertions(+), 18 deletions(-)
---
diff --git a/gio/tests/memory-monitor.c b/gio/tests/memory-monitor.c
index 06eabefa2..31feca26a 100644
--- a/gio/tests/memory-monitor.c
+++ b/gio/tests/memory-monitor.c
@@ -18,21 +18,6 @@
 
 #include <gio/gio.h>
 
-static const char *
-get_level_string (GMemoryMonitorWarningLevel level)
-{
-  GEnumClass *eclass;
-  GEnumValue *value;
-
-  eclass = G_ENUM_CLASS (g_type_class_peek (G_TYPE_MEMORY_MONITOR_WARNING_LEVEL));
-  value = g_enum_get_value (eclass, level);
-
-  if (value == NULL)
-    return "unknown";
-
-  return value->value_nick;
-}
-
 static void
 test_dup_default (void)
 {
@@ -47,10 +32,9 @@ static void
 warning_cb (GMemoryMonitor *m,
            GMemoryMonitorWarningLevel level)
 {
-  const char *str;
-
-  str = get_level_string (level);
+  char *str = g_enum_to_string (G_TYPE_MEMORY_MONITOR_WARNING_LEVEL, level);
   g_debug ("Warning level: %s (%d)", str , level);
+  g_free (str);
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]