diff options
Diffstat (limited to 'gprof/cg_arcs.c')
-rw-r--r-- | gprof/cg_arcs.c | 51 |
1 files changed, 22 insertions, 29 deletions
diff --git a/gprof/cg_arcs.c b/gprof/cg_arcs.c index cfffb09..9085be0 100644 --- a/gprof/cg_arcs.c +++ b/gprof/cg_arcs.c @@ -89,7 +89,7 @@ void arc_add (Sym *parent, Sym *child, unsigned long count) { static unsigned int maxarcs = 0; - Arc *arc, **newarcs; + Arc *arc; DBG (TALLYDEBUG, printf ("[arc_add] %lu arcs from %s to %s\n", count, parent->name, child->name)); @@ -124,17 +124,7 @@ arc_add (Sym *parent, Sym *child, unsigned long count) maxarcs = 1; maxarcs *= 2; - /* Allocate the new array. */ - newarcs = (Arc **)xmalloc(sizeof (Arc *) * maxarcs); - - /* Copy the old array's contents into the new array. */ - memcpy (newarcs, arcs, numarcs * sizeof (Arc *)); - - /* Free up the old array. */ - free (arcs); - - /* And make the new array be the current array. */ - arcs = newarcs; + arcs = xrealloc (arcs, sizeof (*arcs) * maxarcs); } /* Place this arc in the arc array. */ @@ -275,11 +265,12 @@ cycle_link (void) Sym *sym, *cyc, *member; Arc *arc; int num; + Sym_Table *symtab = get_symtab (); /* count the number of cycles, and initialize the cycle lists: */ num_cycles = 0; - for (sym = symtab.base; sym < symtab.limit; ++sym) + for (sym = symtab->base; sym < symtab->limit; ++sym) { /* this is how you find unattached cycles: */ if (sym->cg.cyc.head == sym && sym->cg.cyc.next) @@ -300,7 +291,7 @@ cycle_link (void) */ num = 0; cyc = cycle_header; - for (sym = symtab.base; sym < symtab.limit; ++sym) + for (sym = symtab->base; sym < symtab->limit; ++sym) { if (!(sym->cg.cyc.head == sym && sym->cg.cyc.next != 0)) { @@ -440,9 +431,10 @@ propagate_flags (Sym **symbols) { int sym_index; Sym *old_head, *child; + Sym_Table *symtab = get_symtab (); old_head = 0; - for (sym_index = symtab.len - 1; sym_index >= 0; --sym_index) + for (sym_index = symtab->len - 1; sym_index >= 0; --sym_index) { child = symbols[sym_index]; /* @@ -597,12 +589,13 @@ cg_assemble (void) Sym *parent, **time_sorted_syms, **top_sorted_syms; unsigned int sym_index; Arc *arc; + Sym_Table *symtab = get_symtab (); /* Initialize various things: Zero out child times. Count self-recursive calls. Indicate that nothing is on cycles. */ - for (parent = symtab.base; parent < symtab.limit; parent++) + for (parent = symtab->base; parent < symtab->limit; parent++) { parent->cg.child_time = 0.0; arc = arc_lookup (parent, parent); @@ -633,7 +626,7 @@ cg_assemble (void) /* Topologically order things. If any node is unnumbered, number it and any of its descendents. */ - for (parent = symtab.base; parent < symtab.limit; parent++) + for (parent = symtab->base; parent < symtab->limit; parent++) { if (parent->cg.top_order == DFN_NAN) cg_dfn (parent); @@ -643,14 +636,14 @@ cg_assemble (void) cycle_link (); /* Sort the symbol table in reverse topological order. */ - top_sorted_syms = (Sym **) xmalloc (symtab.len * sizeof (Sym *)); - for (sym_index = 0; sym_index < symtab.len; ++sym_index) - top_sorted_syms[sym_index] = &symtab.base[sym_index]; + top_sorted_syms = (Sym **) xmalloc (symtab->len * sizeof (Sym *)); + for (sym_index = 0; sym_index < symtab->len; ++sym_index) + top_sorted_syms[sym_index] = &symtab->base[sym_index]; - qsort (top_sorted_syms, symtab.len, sizeof (Sym *), cmp_topo); + qsort (top_sorted_syms, symtab->len, sizeof (Sym *), cmp_topo); DBG (DFNDEBUG, printf ("[cg_assemble] topological sort listing\n"); - for (sym_index = 0; sym_index < symtab.len; ++sym_index) + for (sym_index = 0; sym_index < symtab->len; ++sym_index) { printf ("[cg_assemble] "); printf ("%d:", top_sorted_syms[sym_index]->cg.top_order); @@ -668,24 +661,24 @@ cg_assemble (void) /* Starting from the topological bottom, propagate children times up to parents. */ cycle_time (); - for (sym_index = 0; sym_index < symtab.len; ++sym_index) + for (sym_index = 0; sym_index < symtab->len; ++sym_index) propagate_time (top_sorted_syms[sym_index]); free (top_sorted_syms); /* Now, sort by CG.PROP.SELF + CG.PROP.CHILD. Sorting both the regular function names and cycle headers. */ - time_sorted_syms = (Sym **) xmalloc ((symtab.len + num_cycles) * sizeof (Sym *)); - for (sym_index = 0; sym_index < symtab.len; sym_index++) - time_sorted_syms[sym_index] = &symtab.base[sym_index]; + time_sorted_syms = (Sym **) xmalloc ((symtab->len + num_cycles) * sizeof (Sym *)); + for (sym_index = 0; sym_index < symtab->len; sym_index++) + time_sorted_syms[sym_index] = &symtab->base[sym_index]; for (sym_index = 1; sym_index <= num_cycles; sym_index++) - time_sorted_syms[symtab.len + sym_index - 1] = &cycle_header[sym_index]; + time_sorted_syms[symtab->len + sym_index - 1] = &cycle_header[sym_index]; - qsort (time_sorted_syms, symtab.len + num_cycles, sizeof (Sym *), + qsort (time_sorted_syms, symtab->len + num_cycles, sizeof (Sym *), cmp_total); - for (sym_index = 0; sym_index < symtab.len + num_cycles; sym_index++) + for (sym_index = 0; sym_index < symtab->len + num_cycles; sym_index++) time_sorted_syms[sym_index]->cg.index = sym_index + 1; return time_sorted_syms; |