diff options
author | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-05-02 13:59:38 +0000 |
---|---|---|
committer | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-05-02 13:59:38 +0000 |
commit | 73c6d54e2cd9732b48f35516124b6848cff88e2d (patch) | |
tree | 849d92074f65867ad3f1ba5437908e05b47c65e5 /gcc/graphds.c | |
parent | 7007400071d3afc1525ca1691c93ae77c509349f (diff) | |
download | gcc-73c6d54e2cd9732b48f35516124b6848cff88e2d.tar.gz |
2013-05-02 Richard Biener <rguenther@suse.de>
* graphds.h (struct graph): Add obstack member.
* graphds.c (new_graph): Initialize obstack and allocate
vertices from it.
(add_edge): Allocate edge from the obstack.
(free_graph): Free the obstack instead of all edges and
vertices.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@198539 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/graphds.c')
-rw-r--r-- | gcc/graphds.c | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/gcc/graphds.c b/gcc/graphds.c index 3d64d8988cd..d009c1375c2 100644 --- a/gcc/graphds.c +++ b/gcc/graphds.c @@ -58,8 +58,10 @@ new_graph (int n_vertices) { struct graph *g = XNEW (struct graph); + gcc_obstack_init (&g->ob); g->n_vertices = n_vertices; - g->vertices = XCNEWVEC (struct vertex, n_vertices); + g->vertices = XOBNEWVEC (&g->ob, struct vertex, n_vertices); + memset (g->vertices, 0, sizeof (struct vertex) * n_vertices); return g; } @@ -69,10 +71,9 @@ new_graph (int n_vertices) struct graph_edge * add_edge (struct graph *g, int f, int t) { - struct graph_edge *e = XNEW (struct graph_edge); + struct graph_edge *e = XOBNEW (&g->ob, struct graph_edge); struct vertex *vf = &g->vertices[f], *vt = &g->vertices[t]; - e->src = f; e->dest = t; @@ -324,20 +325,7 @@ for_each_edge (struct graph *g, graphds_edge_callback callback) void free_graph (struct graph *g) { - struct graph_edge *e, *n; - struct vertex *v; - int i; - - for (i = 0; i < g->n_vertices; i++) - { - v = &g->vertices[i]; - for (e = v->succ; e; e = n) - { - n = e->succ_next; - free (e); - } - } - free (g->vertices); + obstack_free (&g->ob, NULL); free (g); } |