From 2c9c41dedcceffbb2d56036dc0e21a1a41cca39c Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Mon, 12 Jun 2023 11:34:04 -0700 Subject: [PATCH] libsysprof-analyze: allow specifying ptr array for symbols This will allow us to use the same model with a different list of symbols. --- .../sysprof-callgraph-symbol-private.h | 3 +- .../sysprof-callgraph-symbol.c | 38 +++++++++++++++---- src/libsysprof-analyze/sysprof-callgraph.c | 2 +- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/libsysprof-analyze/sysprof-callgraph-symbol-private.h b/src/libsysprof-analyze/sysprof-callgraph-symbol-private.h index 1c3adc97..5fb61cf0 100644 --- a/src/libsysprof-analyze/sysprof-callgraph-symbol-private.h +++ b/src/libsysprof-analyze/sysprof-callgraph-symbol-private.h @@ -24,6 +24,7 @@ G_BEGIN_DECLS -GListModel *_sysprof_callgraph_symbol_list_model_new (SysprofCallgraph *callgraph); +GListModel *_sysprof_callgraph_symbol_list_model_new (SysprofCallgraph *callgraph, + GPtrArray *symbols); G_END_DECLS diff --git a/src/libsysprof-analyze/sysprof-callgraph-symbol.c b/src/libsysprof-analyze/sysprof-callgraph-symbol.c index 9fe8a31a..370d5440 100644 --- a/src/libsysprof-analyze/sysprof-callgraph-symbol.c +++ b/src/libsysprof-analyze/sysprof-callgraph-symbol.c @@ -171,16 +171,22 @@ sysprof_callgraph_symbol_get_callgraph (SysprofCallgraphSymbol *self) return self->callgraph; } -struct _SysprofCallgraphSymbolListModel +typedef struct _SysprofCallgraphSymbolListModel { GObject parent_instance; SysprofCallgraph *callgraph; -}; + GPtrArray *symbols; +} SysprofCallgraphSymbolListModel; static guint sysprof_callgraph_symbol_list_model_get_n_items (GListModel *model) { - return SYSPROF_CALLGRAPH_SYMBOL (model)->callgraph->symbols->len; + SysprofCallgraphSymbolListModel *self = (SysprofCallgraphSymbolListModel *)model; + + if (self->symbols != NULL) + return self->symbols->len; + + return 0; } static GType @@ -193,13 +199,13 @@ static gpointer sysprof_callgraph_symbol_list_model_get_item (GListModel *model, guint position) { - SysprofCallgraphSymbol *self = SYSPROF_CALLGRAPH_SYMBOL (model); + SysprofCallgraphSymbolListModel *self = (SysprofCallgraphSymbolListModel *)model; - if (position >= self->callgraph->symbols->len) + if (self->symbols == NULL || position >= self->symbols->len) return NULL; return _sysprof_callgraph_symbol_new (self->callgraph, - g_ptr_array_index (self->callgraph->symbols, position)); + g_ptr_array_index (self->symbols, position)); } static void @@ -215,9 +221,23 @@ G_DECLARE_FINAL_TYPE (SysprofCallgraphSymbolListModel, sysprof_callgraph_symbol_ G_DEFINE_FINAL_TYPE_WITH_CODE (SysprofCallgraphSymbolListModel, sysprof_callgraph_symbol_list_model, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, list_model_iface_init)) +static void +sysprof_callgraph_symbol_list_model_dispose (GObject *object) +{ + SysprofCallgraphSymbolListModel *self = (SysprofCallgraphSymbolListModel *)object; + + g_clear_pointer (&self->symbols, g_ptr_array_unref); + g_clear_object (&self->callgraph); + + G_OBJECT_CLASS (sysprof_callgraph_symbol_parent_class)->dispose (object); +} + static void sysprof_callgraph_symbol_list_model_class_init (SysprofCallgraphSymbolListModelClass *klass) { + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = sysprof_callgraph_symbol_list_model_dispose; } static void @@ -226,7 +246,8 @@ sysprof_callgraph_symbol_list_model_init (SysprofCallgraphSymbolListModel *self) } GListModel * -_sysprof_callgraph_symbol_list_model_new (SysprofCallgraph *callgraph) +_sysprof_callgraph_symbol_list_model_new (SysprofCallgraph *callgraph, + GPtrArray *symbols) { SysprofCallgraphSymbolListModel *self; @@ -235,6 +256,9 @@ _sysprof_callgraph_symbol_list_model_new (SysprofCallgraph *callgraph) self = g_object_new (SYSPROF_TYPE_CALLGRAPH_SYMBOL_LIST_MODEL, NULL); self->callgraph = g_object_ref (callgraph); + if (symbols != NULL) + self->symbols = g_ptr_array_ref (symbols); + return G_LIST_MODEL (self); } diff --git a/src/libsysprof-analyze/sysprof-callgraph.c b/src/libsysprof-analyze/sysprof-callgraph.c index 464c893b..b56bb32e 100644 --- a/src/libsysprof-analyze/sysprof-callgraph.c +++ b/src/libsysprof-analyze/sysprof-callgraph.c @@ -528,5 +528,5 @@ sysprof_callgraph_list_symbols (SysprofCallgraph *self) { g_return_val_if_fail (SYSPROF_IS_CALLGRAPH (self), NULL); - return _sysprof_callgraph_symbol_list_model_new (self); + return _sysprof_callgraph_symbol_list_model_new (self, self->symbols); }