From 15844df5b95817c2f36b82f2678c013021332fcf Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Thu, 12 Sep 2024 10:52:41 -0700 Subject: [PATCH] callgraph: use bump allocator for callgraph nodes --- src/libsysprof/sysprof-callgraph-private.h | 3 +++ src/libsysprof/sysprof-callgraph.c | 21 +++------------------ src/libsysprof/sysprof-descendants-model.c | 17 ++++++++++------- 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/libsysprof/sysprof-callgraph-private.h b/src/libsysprof/sysprof-callgraph-private.h index 9ccf94aa..56d3a5b6 100644 --- a/src/libsysprof/sysprof-callgraph-private.h +++ b/src/libsysprof/sysprof-callgraph-private.h @@ -22,6 +22,7 @@ #include +#include "sysprof-allocator-private.h" #include "sysprof-callgraph.h" #include "sysprof-document.h" @@ -57,6 +58,8 @@ struct _SysprofCallgraph { GObject parent_instance; + SysprofAllocator *allocator; + SysprofDocument *document; GListModel *traceables; diff --git a/src/libsysprof/sysprof-callgraph.c b/src/libsysprof/sysprof-callgraph.c index c91ba900..f0167f15 100644 --- a/src/libsysprof/sysprof-callgraph.c +++ b/src/libsysprof/sysprof-callgraph.c @@ -113,22 +113,6 @@ sysprof_callgraph_get_summary (SysprofCallgraph *self, return summary; } -void -_sysprof_callgraph_node_free (SysprofCallgraphNode *node, - gboolean free_self) -{ - SysprofCallgraphNode *iter = node->children; - - while (iter) - { - SysprofCallgraphNode *to_free = iter; - iter = iter->next; - _sysprof_callgraph_node_free (to_free, TRUE); - } - - if (free_self) - g_free (node); -} static void sysprof_callgraph_dispose (GObject *object) @@ -159,7 +143,7 @@ sysprof_callgraph_finalize (GObject *object) g_clear_object (&self->document); g_clear_object (&self->traceables); - _sysprof_callgraph_node_free (&self->root, FALSE); + g_clear_pointer (&self->allocator, sysprof_allocator_unref); G_OBJECT_CLASS (sysprof_callgraph_parent_class)->finalize (object); } @@ -183,6 +167,7 @@ sysprof_callgraph_class_init (SysprofCallgraphClass *klass) static void sysprof_callgraph_init (SysprofCallgraph *self) { + self->allocator = sysprof_allocator_new (); } static void @@ -256,7 +241,7 @@ sysprof_callgraph_add_trace (SysprofCallgraph *self, } /* Otherwise create a new node */ - node = g_new0 (SysprofCallgraphNode, 1); + node = sysprof_allocator_new0 (self->allocator, SysprofCallgraphNode); node->summary = sysprof_callgraph_get_summary (self, symbol); node->parent = parent; node->next = parent->children; diff --git a/src/libsysprof/sysprof-descendants-model.c b/src/libsysprof/sysprof-descendants-model.c index 7d6ea2ec..e0c9b604 100644 --- a/src/libsysprof/sysprof-descendants-model.c +++ b/src/libsysprof/sysprof-descendants-model.c @@ -20,6 +20,7 @@ #include "config.h" +#include "sysprof-allocator-private.h" #include "sysprof-callgraph-private.h" #include "sysprof-callgraph-frame-private.h" #include "sysprof-descendants-model-private.h" @@ -30,10 +31,11 @@ struct _SysprofDescendantsModel { - GObject parent_instance; - SysprofCallgraph *callgraph; - SysprofSymbol *symbol; - SysprofCallgraphNode root; + GObject parent_instance; + SysprofAllocator *allocator; + SysprofCallgraph *callgraph; + SysprofSymbol *symbol; + SysprofCallgraphNode root; }; static GType @@ -76,11 +78,11 @@ sysprof_descendants_model_finalize (GObject *object) { SysprofDescendantsModel *self = (SysprofDescendantsModel *)object; - _sysprof_callgraph_node_free (&self->root, FALSE); - g_clear_object (&self->callgraph); g_clear_object (&self->symbol); + g_clear_pointer (&self->allocator, sysprof_allocator_unref); + G_OBJECT_CLASS (sysprof_descendants_model_parent_class)->finalize (object); } @@ -95,6 +97,7 @@ sysprof_descendants_model_class_init (SysprofDescendantsModelClass *klass) static void sysprof_descendants_model_init (SysprofDescendantsModel *self) { + self->allocator = sysprof_allocator_new (); } static SysprofCallgraphNode * @@ -141,7 +144,7 @@ sysprof_descendants_model_add_trace (SysprofDescendantsModel *self, } /* Otherwise create a new node */ - node = g_new0 (SysprofCallgraphNode, 1); + node = sysprof_allocator_new0 (self->allocator, SysprofCallgraphNode); node->summary = summary; node->parent = parent; node->next = parent->children;