From c245776906b065fcd59831a25c3b24ad3ddcd849 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 16 Jul 2019 13:12:24 -0400 Subject: Remove lappend_cell...() family of List functions. It seems worth getting rid of these functions because they require the caller to retain a ListCell pointer into a List that it's modifying, which is a dangerous practice with the new List implementation. (The only other List-modifying function that takes a ListCell pointer as input is list_delete_cell, which nowadays is preferentially used via the constrained API foreach_delete_current.) There was only one remaining caller of these functions after commit 2f5b8eb5a, and that was some fairly ugly GEQO code that can be much more clearly expressed using a list-index variable and list_insert_nth. Hence, rewrite that code, and remove the functions. Discussion: https://postgr.es/m/26193.1563228600@sss.pgh.pa.us --- src/backend/optimizer/geqo/geqo_eval.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'src/backend/optimizer') diff --git a/src/backend/optimizer/geqo/geqo_eval.c b/src/backend/optimizer/geqo/geqo_eval.c index 8a44ac8530d..7b67a29c88a 100644 --- a/src/backend/optimizer/geqo/geqo_eval.c +++ b/src/backend/optimizer/geqo/geqo_eval.c @@ -239,6 +239,7 @@ merge_clump(PlannerInfo *root, List *clumps, Clump *new_clump, int num_gene, bool force) { ListCell *lc; + int pos; /* Look for a clump that new_clump can join to */ foreach(lc, clumps) @@ -304,21 +305,15 @@ merge_clump(PlannerInfo *root, List *clumps, Clump *new_clump, int num_gene, if (clumps == NIL || new_clump->size == 1) return lappend(clumps, new_clump); - /* Check if it belongs at the front */ - lc = list_head(clumps); - if (new_clump->size > ((Clump *) lfirst(lc))->size) - return lcons(new_clump, clumps); - /* Else search for the place to insert it */ - for (;;) + for (pos = 0; pos < list_length(clumps); pos++) { - ListCell *nxt = lnext(clumps, lc); + Clump *old_clump = (Clump *) list_nth(clumps, pos); - if (nxt == NULL || new_clump->size > ((Clump *) lfirst(nxt))->size) - break; /* it belongs after 'lc', before 'nxt' */ - lc = nxt; + if (new_clump->size > old_clump->size) + break; /* new_clump belongs before old_clump */ } - lappend_cell(clumps, lc, new_clump); + clumps = list_insert_nth(clumps, pos, new_clump); return clumps; } -- cgit v1.2.3