=== modified file 'gcc/graphds.c'
@@ -62,7 +62,8 @@ new_graph (int n_vertices)
g->n_vertices = n_vertices;
g->vertices = XCNEWVEC (struct vertex, n_vertices);
-
+ g->edge_pool = create_alloc_pool ("edge_pool",
+ sizeof (struct graph_edge), 32);
return g;
}
@@ -71,7 +72,7 @@ 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 = (struct graph_edge *) pool_alloc (g->edge_pool);
struct vertex *vf = &g->vertices[f], *vt = &g->vertices[t];
@@ -326,19 +327,7 @@ for_each_edge (struct graph *g, graphds_
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_alloc_pool (g->edge_pool);
free (g->vertices);
free (g);
}
=== modified file 'gcc/graphds.h'
@@ -18,6 +18,10 @@ You should have received a copy of the G
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
+
+#include "alloc-pool.h"
+
+
/* Structure representing edge of a graph. */
struct graph_edge
@@ -44,10 +48,10 @@ struct vertex
struct graph
{
- int n_vertices; /* Number of vertices. */
- struct vertex *vertices;
- /* The vertices. */
- htab_t indices; /* Fast lookup for indices. */
+ int n_vertices; /* Number of vertices. */
+ struct vertex *vertices; /* The vertices. */
+ htab_t indices; /* Fast lookup for indices. */
+ alloc_pool edge_pool; /* Pool for allocating edges. */
};
struct graph *new_graph (int);