From: Matthew Fernandez Date: Sat, 5 Nov 2022 02:59:19 +0000 (-0700) Subject: smyrna: remove a level of indirection in the grid column array X-Git-Tag: 7.0.2~18^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b0d68a29cfc31a91d59464fc7f352cbf3e5945ed;p=graphviz smyrna: remove a level of indirection in the grid column array The pointers of this array are never captured, so we can use an array of values here instead. This reduces heap allocation and fragmentation. --- diff --git a/cmd/smyrna/tvnodes.c b/cmd/smyrna/tvnodes.c index ed131f2d5..4402bc7bc 100644 --- a/cmd/smyrna/tvnodes.c +++ b/cmd/smyrna/tvnodes.c @@ -23,7 +23,7 @@ typedef struct { } gridCol; typedef struct { int count; - gridCol **columns; + gridCol *columns; GtkTreeStore *store; char *flds; char *buf; @@ -197,7 +197,6 @@ static void populate_data(Agraph_t * g, grid * grid) GtkTreeIter iter; GValue value = {0}; char* bf; - gridCol* cp; for (v = agfstnode(g); v; v = agnxtnode(g, v)) { if (!ND_selected(v)) @@ -205,7 +204,7 @@ static void populate_data(Agraph_t * g, grid * grid) gtk_tree_store_append(grid->store, &iter, NULL); for (id = 0; id < grid->count; id++) { - cp = grid->columns[id]; + gridCol *cp = &grid->columns[id]; if (strcmp(cp->name, ID) == 0) continue; if (strcmp(cp->name, Name) == 0) @@ -216,7 +215,7 @@ static void populate_data(Agraph_t * g, grid * grid) continue; g_value_init(&value, cp->type); - switch (grid->columns[id]->type) { + switch (grid->columns[id].type) { case G_TYPE_BOOLEAN: if (bf) { if ((strcmp(bf, "1") == 0) || (strcmp(bf, "true") == 0) @@ -294,13 +293,13 @@ static GtkTreeView *update_tree(GtkTreeView * tree, grid * g) if (g->count > 0) { types = gv_calloc((size_t)g->count, sizeof(GType)); for (id = 0; id < g->count; id++) - types[id] = g->columns[id]->type; + types[id] = g->columns[id].type; store = update_tree_store(g->store, g->count, types); free (types); gtk_tree_view_set_model(tree, (GtkTreeModel *) store); /*insert columns */ for (id = 0; id < g->count; id++) - create_column(g->columns[id], tree, id); + create_column(&g->columns[id], tree, id); } g->store = store; return tree; @@ -312,11 +311,10 @@ static void add_column(grid * g, char *name, bool editable, GType g_type) return; assert(g->count >= 0); g->columns = gv_recalloc(g->columns, (size_t)g->count, (size_t)g->count + 1, - sizeof(gridCol*)); - g->columns[g->count] = gv_alloc(sizeof(gridCol)); - g->columns[g->count]->editable = editable; - g->columns[g->count]->name = gv_strdup(name); - g->columns[g->count]->type = g_type; + sizeof(gridCol)); + g->columns[g->count].editable = editable; + g->columns[g->count].name = gv_strdup(name); + g->columns[g->count].type = g_type; g->count++; } @@ -324,8 +322,7 @@ static void clearGrid(grid * g) { int id; for (id = 0; id < g->count; id++) { - free(g->columns[id]->name); - free(g->columns[id]); + free(g->columns[id].name); } free(g->columns); free(g->buf);