From 0785f32ce5413719d991a40e10a16adafe0f9358 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 2 Jul 2020 10:13:26 +0100 Subject: [PATCH] libsysprof-capture: Use SYSPROF_N_ELEMENTS macro instead of G_N_ELEMENTS It does the same thing. Signed-off-by: Philip Withnall Helps: #40 --- .../sysprof-capture-reader.c | 2 +- .../sysprof-capture-writer-cat.c | 2 +- .../sysprof-capture-writer.c | 20 +++++++++---------- src/libsysprof-capture/sysprof-clock.c | 2 +- .../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 94de783b..537c3a94 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 2cd71f4b..3fbd5858 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 d85b5f5a..67713063 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 7543e027..cbaafa1c 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 eacec0da..9fed4652 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) \