mirror of
https://github.com/postgres/postgres.git
synced 2025-09-06 13:46:51 +03:00
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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user