From: Matthew Fernandez Date: Thu, 24 Nov 2022 18:52:55 +0000 (-0800) Subject: ortho: push trapezoids allocation into 'construct_trapezoids' X-Git-Tag: 7.0.4~2^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1f90006b9da7a40c73b48e9d30d07c4cdf9b575c;p=graphviz ortho: push trapezoids allocation into 'construct_trapezoids' This makes it more obvious to readers and the compiler that the value of this on-entry to `construct_trapezoids` is unimportant and the value does not need to be retained between the two `construct_trapezoids` calls in `partition`. --- diff --git a/lib/ortho/partition.c b/lib/ortho/partition.c index aa972d243..2c7cc00ff 100644 --- a/lib/ortho/partition.c +++ b/lib/ortho/partition.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -690,12 +691,6 @@ partition (cell* cells, int ncells, int* nrects, boxf bb) segment_t* segs = gv_calloc(nsegs + 1, sizeof(segment_t)); int* permute = gv_calloc(nsegs + 1, sizeof(int)); - // First trapezoid is reserved as a sentinel. We will append later - // trapezoids by expanding this on-demand. - traps_t trs = {.length = 1, .data = gv_calloc(1, sizeof(trap_t))}; - - int nt; - if (DEBUG) { fprintf (stderr, "cells = %d segs = %d traps = dynamic\n", ncells, nsegs); } @@ -710,25 +705,23 @@ partition (cell* cells, int ncells, int* nrects, boxf bb) } srand48(173); generateRandomOrdering (nsegs, permute); - nt = construct_trapezoids(nsegs, segs, permute, &trs); + traps_t hor_traps = construct_trapezoids(nsegs, segs, permute); if (DEBUG) { - fprintf (stderr, "hor traps = %d\n", nt); + fprintf (stderr, "hor traps = %" PRISIZE_T "\n", hor_traps.length); } boxes_t hor_decomp = {0}; - monotonate_trapezoids(nsegs, segs, &trs, 0, &hor_decomp); - - // reset trapezoid collection - free(trs.data); - trs = (traps_t){.length = 1, .data = gv_calloc(1, sizeof(trap_t))}; + monotonate_trapezoids(nsegs, segs, &hor_traps, 0, &hor_decomp); + free(hor_traps.data); genSegments (cells, ncells, bb, segs, 1); generateRandomOrdering (nsegs, permute); - nt = construct_trapezoids(nsegs, segs, permute, &trs); + traps_t ver_traps = construct_trapezoids(nsegs, segs, permute); if (DEBUG) { - fprintf (stderr, "ver traps = %d\n", nt); + fprintf (stderr, "ver traps = %" PRISIZE_T "\n", ver_traps.length); } boxes_t vert_decomp = {0}; - monotonate_trapezoids(nsegs, segs, &trs, 1, &vert_decomp); + monotonate_trapezoids(nsegs, segs, &ver_traps, 1, &vert_decomp); + free(ver_traps.data); boxes_t rs = {0}; for (size_t i = 0; i < vert_decomp.size; ++i) @@ -740,7 +733,6 @@ partition (cell* cells, int ncells, int* nrects, boxf bb) free (segs); free (permute); - free(trs.data); boxes_free(&hor_decomp); boxes_free(&vert_decomp); *nrects = rs.size; diff --git a/lib/ortho/trap.h b/lib/ortho/trap.h index 7378a26d3..431741043 100644 --- a/lib/ortho/trap.h +++ b/lib/ortho/trap.h @@ -83,4 +83,4 @@ static inline int dfp_cmp(double f1, double f2) { #define _greater_than(v0, v1) \ (((v0)->y > (v1)->y + C_EPS) ? true : (((v0)->y < (v1)->y - C_EPS) ? false : ((v0)->x > (v1)->x))) -extern int construct_trapezoids(int, segment_t*, int*, traps_t *tr); +extern traps_t construct_trapezoids(int, segment_t*, int*); diff --git a/lib/ortho/trapezoid.c b/lib/ortho/trapezoid.c index 631b9405f..d5ff19f9b 100644 --- a/lib/ortho/trapezoid.c +++ b/lib/ortho/trapezoid.c @@ -1005,8 +1005,7 @@ static int math_N(int n, int h) } /* Main routine to perform trapezoidation */ -int -construct_trapezoids(int nseg, segment_t *seg, int *permute, traps_t* tr) { +traps_t construct_trapezoids(int nseg, segment_t *seg, int *permute) { int i; int root, h; int segi = 1; @@ -1015,26 +1014,30 @@ construct_trapezoids(int nseg, segment_t *seg, int *permute, traps_t* tr) { // sentinel. qnodes_t qs = {.length = 1, .data = gv_calloc(1, sizeof(qnode_t))}; + // First trapezoid is reserved as a sentinel. We will append later + // trapezoids by expanding this on-demand. + traps_t tr = {.length = 1, .data = gv_calloc(1, sizeof(trap_t))}; + /* Add the first segment and get the query structure and trapezoid */ /* list initialised */ - root = init_query_structure(permute[segi++], seg, tr, &qs); + root = init_query_structure(permute[segi++], seg, &tr, &qs); for (i = 1; i <= nseg; i++) seg[i].root0 = seg[i].root1 = root; for (h = 1; h <= math_logstar_n(nseg); h++) { for (i = math_N(nseg, h -1) + 1; i <= math_N(nseg, h); i++) - add_segment(permute[segi++], seg, tr, &qs); + add_segment(permute[segi++], seg, &tr, &qs); /* Find a new root for each of the segment endpoints */ for (i = 1; i <= nseg; i++) - find_new_roots(i, seg, tr, &qs); + find_new_roots(i, seg, &tr, &qs); } for (i = math_N(nseg, math_logstar_n(nseg)) + 1; i <= nseg; i++) - add_segment(permute[segi++], seg, tr, &qs); + add_segment(permute[segi++], seg, &tr, &qs); free(qs.data); - return tr->length; + return tr; }