[gjs: 10/18] mem: Add GJS_FOR_EACH_COUNTER



commit 4b424a081e8ec63810707477abef3654222cd44f
Author: Philip Chimento <philip endlessm com>
Date:   Thu Nov 21 17:37:15 2019 -0800

    mem: Add GJS_FOR_EACH_COUNTER
    
    Add a macro that expands a macro for every counter, instead of having
    long lists of macros being expanded for every counter.

 gjs/mem-private.h | 42 +++++++++++++++++++++++-------------------
 gjs/mem.cpp       | 47 +++--------------------------------------------
 2 files changed, 26 insertions(+), 63 deletions(-)
---
diff --git a/gjs/mem-private.h b/gjs/mem-private.h
index e9819ca0..14b739ac 100644
--- a/gjs/mem-private.h
+++ b/gjs/mem-private.h
@@ -31,28 +31,32 @@ typedef struct {
     const char* name;
 } GjsMemCounter;
 
+// clang-format off
+#define GJS_FOR_EACH_COUNTER(macro) \
+    macro(boxed_instance)           \
+    macro(boxed_prototype)          \
+    macro(closure)                  \
+    macro(function)                 \
+    macro(fundamental_instance)     \
+    macro(fundamental_prototype)    \
+    macro(gerror_instance)          \
+    macro(gerror_prototype)         \
+    macro(importer)                 \
+    macro(interface)                \
+    macro(module)                   \
+    macro(ns)                       \
+    macro(object_instance)          \
+    macro(object_prototype)         \
+    macro(param)                    \
+    macro(repo)                     \
+    macro(union_instance)           \
+    macro(union_prototype)
+// clang-format on
+
 #define GJS_DECLARE_COUNTER(name) extern GjsMemCounter gjs_counter_##name;
 
 GJS_DECLARE_COUNTER(everything)
-
-GJS_DECLARE_COUNTER(boxed_instance)
-GJS_DECLARE_COUNTER(boxed_prototype)
-GJS_DECLARE_COUNTER(closure)
-GJS_DECLARE_COUNTER(function)
-GJS_DECLARE_COUNTER(fundamental_instance)
-GJS_DECLARE_COUNTER(fundamental_prototype)
-GJS_DECLARE_COUNTER(gerror_instance)
-GJS_DECLARE_COUNTER(gerror_prototype)
-GJS_DECLARE_COUNTER(importer)
-GJS_DECLARE_COUNTER(interface)
-GJS_DECLARE_COUNTER(module)
-GJS_DECLARE_COUNTER(ns)
-GJS_DECLARE_COUNTER(object_instance)
-GJS_DECLARE_COUNTER(object_prototype)
-GJS_DECLARE_COUNTER(param)
-GJS_DECLARE_COUNTER(repo)
-GJS_DECLARE_COUNTER(union_instance)
-GJS_DECLARE_COUNTER(union_prototype)
+GJS_FOR_EACH_COUNTER(GJS_DECLARE_COUNTER)
 
 #define GJS_INC_COUNTER(name)                               \
     do {                                                    \
diff --git a/gjs/mem.cpp b/gjs/mem.cpp
index 3e3acb2f..ebf0ded1 100644
--- a/gjs/mem.cpp
+++ b/gjs/mem.cpp
@@ -34,52 +34,11 @@
 
 
 GJS_DEFINE_COUNTER(everything)
+GJS_FOR_EACH_COUNTER(GJS_DEFINE_COUNTER)
 
-GJS_DEFINE_COUNTER(boxed_instance)
-GJS_DEFINE_COUNTER(boxed_prototype)
-GJS_DEFINE_COUNTER(closure)
-GJS_DEFINE_COUNTER(function)
-GJS_DEFINE_COUNTER(fundamental_instance)
-GJS_DEFINE_COUNTER(fundamental_prototype)
-GJS_DEFINE_COUNTER(gerror_instance)
-GJS_DEFINE_COUNTER(gerror_prototype)
-GJS_DEFINE_COUNTER(importer)
-GJS_DEFINE_COUNTER(interface)
-GJS_DEFINE_COUNTER(module)
-GJS_DEFINE_COUNTER(ns)
-GJS_DEFINE_COUNTER(object_instance)
-GJS_DEFINE_COUNTER(object_prototype)
-GJS_DEFINE_COUNTER(param)
-GJS_DEFINE_COUNTER(repo)
-GJS_DEFINE_COUNTER(union_instance)
-GJS_DEFINE_COUNTER(union_prototype)
+#define GJS_LIST_COUNTER(name) &gjs_counter_##name,
 
-#define GJS_LIST_COUNTER(name) \
-    & gjs_counter_ ## name
-
-// clang-format off
-// otherwise these are put into 2 columns?!
-static GjsMemCounter* counters[] = {
-    GJS_LIST_COUNTER(boxed_instance),
-    GJS_LIST_COUNTER(boxed_prototype),
-    GJS_LIST_COUNTER(closure),
-    GJS_LIST_COUNTER(function),
-    GJS_LIST_COUNTER(fundamental_instance),
-    GJS_LIST_COUNTER(fundamental_prototype),
-    GJS_LIST_COUNTER(gerror_instance),
-    GJS_LIST_COUNTER(gerror_prototype),
-    GJS_LIST_COUNTER(importer),
-    GJS_LIST_COUNTER(interface),
-    GJS_LIST_COUNTER(module),
-    GJS_LIST_COUNTER(ns),
-    GJS_LIST_COUNTER(object_instance),
-    GJS_LIST_COUNTER(object_prototype),
-    GJS_LIST_COUNTER(param),
-    GJS_LIST_COUNTER(repo),
-    GJS_LIST_COUNTER(union_instance),
-    GJS_LIST_COUNTER(union_prototype),
-};
-// clang-format on
+static GjsMemCounter* counters[] = {GJS_FOR_EACH_COUNTER(GJS_LIST_COUNTER)};
 
 void
 gjs_memory_report(const char *where,


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