[sysprof: 27/63] libsysprof-capture: Use SYSPROF_N_ELEMENTS macro instead of G_N_ELEMENTS



commit 0785f32ce5413719d991a40e10a16adafe0f9358
Author: Philip Withnall <withnall endlessm com>
Date:   Thu Jul 2 10:13:26 2020 +0100

    libsysprof-capture: Use SYSPROF_N_ELEMENTS macro instead of G_N_ELEMENTS
    
    It does the same thing.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>
    
    Helps: #40

 src/libsysprof-capture/sysprof-capture-reader.c     |  2 +-
 src/libsysprof-capture/sysprof-capture-writer-cat.c |  2 +-
 src/libsysprof-capture/sysprof-capture-writer.c     | 20 ++++++++++----------
 src/libsysprof-capture/sysprof-clock.c              |  2 +-
 src/libsysprof-capture/sysprof-macros-internal.h    |  2 ++
 5 files changed, 15 insertions(+), 13 deletions(-)
---
diff --git a/src/libsysprof-capture/sysprof-capture-reader.c b/src/libsysprof-capture/sysprof-capture-reader.c
index 94de783..537c3a9 100644
--- a/src/libsysprof-capture/sysprof-capture-reader.c
+++ b/src/libsysprof-capture/sysprof-capture-reader.c
@@ -953,7 +953,7 @@ sysprof_capture_reader_read_counter_set (SysprofCaptureReader *self)
         {
           unsigned int j;
 
-          for (j = 0; j < G_N_ELEMENTS (set->values[0].values); j++)
+          for (j = 0; j < SYSPROF_N_ELEMENTS (set->values[0].values); j++)
             {
               set->values[i].ids[j] = GUINT32_SWAP_LE_BE (set->values[i].ids[j]);
               set->values[i].values[j].v64 = GUINT64_SWAP_LE_BE (set->values[i].values[j].v64);
diff --git a/src/libsysprof-capture/sysprof-capture-writer-cat.c 
b/src/libsysprof-capture/sysprof-capture-writer-cat.c
index 2cd71f4..3fbd585 100644
--- a/src/libsysprof-capture/sysprof-capture-writer-cat.c
+++ b/src/libsysprof-capture/sysprof-capture-writer-cat.c
@@ -446,7 +446,7 @@ sysprof_capture_writer_cat (SysprofCaptureWriter  *self,
                 {
                   const SysprofCaptureCounterValues *v = &frame->values[z];
 
-                  for (unsigned int y = 0; y < G_N_ELEMENTS (v->ids); y++)
+                  for (unsigned int y = 0; y < SYSPROF_N_ELEMENTS (v->ids); y++)
                     {
                       if (v->ids[y])
                         {
diff --git a/src/libsysprof-capture/sysprof-capture-writer.c b/src/libsysprof-capture/sysprof-capture-writer.c
index d85b5f5..6771306 100644
--- a/src/libsysprof-capture/sysprof-capture-writer.c
+++ b/src/libsysprof-capture/sysprof-capture-writer.c
@@ -356,9 +356,9 @@ sysprof_capture_writer_lookup_jitmap (SysprofCaptureWriter  *self,
   assert (name != NULL);
   assert (addr != NULL);
 
-  hash = str_hash (name) % G_N_ELEMENTS (self->addr_hash);
+  hash = str_hash (name) % SYSPROF_N_ELEMENTS (self->addr_hash);
 
-  for (i = hash; i < G_N_ELEMENTS (self->addr_hash); i++)
+  for (i = hash; i < SYSPROF_N_ELEMENTS (self->addr_hash); i++)
     {
       SysprofCaptureJitmapBucket *bucket = &self->addr_hash[i];
 
@@ -405,7 +405,7 @@ sysprof_capture_writer_insert_jitmap (SysprofCaptureWriter *self,
 
   len = sizeof addr + strlen (str) + 1;
 
-  if ((self->addr_hash_size == G_N_ELEMENTS (self->addr_hash)) ||
+  if ((self->addr_hash_size == SYSPROF_N_ELEMENTS (self->addr_hash)) ||
       ((sizeof self->addr_buf - self->addr_buf_pos) < len))
     {
       if (!sysprof_capture_writer_flush_jitmap (self))
@@ -415,7 +415,7 @@ sysprof_capture_writer_insert_jitmap (SysprofCaptureWriter *self,
       assert (self->addr_buf_pos == 0);
     }
 
-  assert (self->addr_hash_size < G_N_ELEMENTS (self->addr_hash));
+  assert (self->addr_hash_size < SYSPROF_N_ELEMENTS (self->addr_hash));
   assert (len > sizeof addr);
 
   /* Allocate the next unique address */
@@ -437,10 +437,10 @@ sysprof_capture_writer_insert_jitmap (SysprofCaptureWriter *self,
   assert (self->addr_buf_pos <= sizeof self->addr_buf);
 
   /* Now place the address into the hashtable */
-  hash = str_hash (str) % G_N_ELEMENTS (self->addr_hash);
+  hash = str_hash (str) % SYSPROF_N_ELEMENTS (self->addr_hash);
 
   /* Start from the current hash bucket and go forward */
-  for (i = hash; i < G_N_ELEMENTS (self->addr_hash); i++)
+  for (i = hash; i < SYSPROF_N_ELEMENTS (self->addr_hash); i++)
     {
       SysprofCaptureJitmapBucket *bucket = &self->addr_hash[i];
 
@@ -1256,8 +1256,8 @@ sysprof_capture_writer_set_counters (SysprofCaptureWriter             *self,
     return true;
 
   /* Determine how many value groups we need */
-  n_groups = n_counters / G_N_ELEMENTS (set->values[0].values);
-  if ((n_groups * G_N_ELEMENTS (set->values[0].values)) != n_counters)
+  n_groups = n_counters / SYSPROF_N_ELEMENTS (set->values[0].values);
+  if ((n_groups * SYSPROF_N_ELEMENTS (set->values[0].values)) != n_counters)
     n_groups++;
 
   len = sizeof *set + (n_groups * sizeof (SysprofCaptureCounterValues));
@@ -1285,7 +1285,7 @@ sysprof_capture_writer_set_counters (SysprofCaptureWriter             *self,
 
       field++;
 
-      if (field == G_N_ELEMENTS (set->values[0].values))
+      if (field == SYSPROF_N_ELEMENTS (set->values[0].values))
         {
           field = 0;
           group++;
@@ -1659,7 +1659,7 @@ _sysprof_capture_writer_add_raw (SysprofCaptureWriter      *self,
 
   memcpy (begin, fr, fr->len);
 
-  if (fr->type < G_N_ELEMENTS (self->stat.frame_count))
+  if (fr->type < SYSPROF_N_ELEMENTS (self->stat.frame_count))
     self->stat.frame_count[fr->type]++;
 
   return true;
diff --git a/src/libsysprof-capture/sysprof-clock.c b/src/libsysprof-capture/sysprof-clock.c
index 7543e02..cbaafa1 100644
--- a/src/libsysprof-capture/sysprof-clock.c
+++ b/src/libsysprof-capture/sysprof-clock.c
@@ -80,7 +80,7 @@ sysprof_clock_init (void)
   if (sysprof_clock != -1)
     return;
 
-  for (unsigned int i = 0; i < G_N_ELEMENTS (clock_ids); i++)
+  for (unsigned int i = 0; i < SYSPROF_N_ELEMENTS (clock_ids); i++)
     {
       struct timespec ts;
       int clock_id = clock_ids [i];
diff --git a/src/libsysprof-capture/sysprof-macros-internal.h 
b/src/libsysprof-capture/sysprof-macros-internal.h
index eacec0d..9fed465 100644
--- a/src/libsysprof-capture/sysprof-macros-internal.h
+++ b/src/libsysprof-capture/sysprof-macros-internal.h
@@ -61,6 +61,8 @@
 
 #define sysprof_assert_not_reached() assert (false)
 
+#define SYSPROF_N_ELEMENTS(a) (sizeof (a) / sizeof (*a))
+
 #define sysprof_steal_pointer(pp) __extension__ ({__typeof(*(pp)) _p = *(pp); *(pp) = NULL; _p;})
 
 #define sysprof_clear_pointer(pp, destroy) \


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