diff options
| author | Tom Lane | 2019-07-16 17:12:24 +0000 |
|---|---|---|
| committer | Tom Lane | 2019-07-16 17:12:24 +0000 |
| commit | c245776906b065fcd59831a25c3b24ad3ddcd849 (patch) | |
| tree | 7bcc6c8dc1d4960e65592726a662d5952b318e3c /src/backend/optimizer | |
| parent | 2f5b8eb5a28b4e6de9d20cc7d2c6028c6c7a8aa8 (diff) | |
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
Diffstat (limited to 'src/backend/optimizer')
| -rw-r--r-- | src/backend/optimizer/geqo/geqo_eval.c | 17 |
1 files changed, 6 insertions, 11 deletions
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; } |
