Commit 2c41c19d by Richard Biener Committed by Richard Biener

graphds.h (struct graph): Add obstack member.

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.

From-SVN: r198539
parent 8b47039c
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.
2013-05-02 Teresa Johnson <tejohnson@google.com> 2013-05-02 Teresa Johnson <tejohnson@google.com>
* loop-unswitch.c (unswitch_loop): Use helper routines with rounding * loop-unswitch.c (unswitch_loop): Use helper routines with rounding
......
...@@ -58,8 +58,10 @@ new_graph (int n_vertices) ...@@ -58,8 +58,10 @@ new_graph (int n_vertices)
{ {
struct graph *g = XNEW (struct graph); struct graph *g = XNEW (struct graph);
gcc_obstack_init (&g->ob);
g->n_vertices = n_vertices; 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; return g;
} }
...@@ -69,10 +71,9 @@ new_graph (int n_vertices) ...@@ -69,10 +71,9 @@ new_graph (int n_vertices)
struct graph_edge * struct graph_edge *
add_edge (struct graph *g, int f, int t) 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]; struct vertex *vf = &g->vertices[f], *vt = &g->vertices[t];
e->src = f; e->src = f;
e->dest = t; e->dest = t;
...@@ -324,20 +325,7 @@ for_each_edge (struct graph *g, graphds_edge_callback callback) ...@@ -324,20 +325,7 @@ for_each_edge (struct graph *g, graphds_edge_callback callback)
void void
free_graph (struct graph *g) free_graph (struct graph *g)
{ {
struct graph_edge *e, *n; obstack_free (&g->ob, NULL);
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);
free (g); free (g);
} }
......
...@@ -43,9 +43,9 @@ struct vertex ...@@ -43,9 +43,9 @@ struct vertex
struct graph struct graph
{ {
int n_vertices; /* Number of vertices. */ int n_vertices; /* Number of vertices. */
struct vertex *vertices; struct vertex *vertices; /* The vertices. */
/* The vertices. */ struct obstack ob; /* Obstack for vertex and edge allocation. */
}; };
struct graph *new_graph (int); struct graph *new_graph (int);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment