Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c245776

Browse files
committed
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 2f5b8eb, 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
1 parent 2f5b8eb commit c245776

File tree

3 files changed

+6
-62
lines changed

3 files changed

+6
-62
lines changed

src/backend/nodes/list.c

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -438,53 +438,6 @@ list_insert_nth_oid(List *list, int pos, Oid datum)
438438
return list;
439439
}
440440

441-
/*
442-
* Add a new cell to the list, in the position after 'prev_cell'. The
443-
* data in the cell is left undefined, and must be filled in by the
444-
* caller. 'list' is assumed to be non-NIL, and 'prev_cell' is assumed
445-
* to be non-NULL and a member of 'list'. Returns address of new cell.
446-
*
447-
* Caution: prev_cell might no longer point into the list after this!
448-
*/
449-
static ListCell *
450-
add_new_cell_after(List *list, ListCell *prev_cell)
451-
{
452-
/* insert_new_cell will assert that this is in-range: */
453-
int pos = prev_cell - list->elements;
454-
455-
return insert_new_cell(list, pos + 1);
456-
}
457-
458-
/*
459-
* Add a new cell to the specified list (which must be non-NIL);
460-
* it will be placed after the list cell 'prev' (which must be
461-
* non-NULL and a member of 'list'). The data placed in the new cell
462-
* is 'datum'.
463-
*/
464-
void
465-
lappend_cell(List *list, ListCell *prev, void *datum)
466-
{
467-
Assert(IsPointerList(list));
468-
lfirst(add_new_cell_after(list, prev)) = datum;
469-
check_list_invariants(list);
470-
}
471-
472-
void
473-
lappend_cell_int(List *list, ListCell *prev, int datum)
474-
{
475-
Assert(IsIntegerList(list));
476-
lfirst_int(add_new_cell_after(list, prev)) = datum;
477-
check_list_invariants(list);
478-
}
479-
480-
void
481-
lappend_cell_oid(List *list, ListCell *prev, Oid datum)
482-
{
483-
Assert(IsOidList(list));
484-
lfirst_oid(add_new_cell_after(list, prev)) = datum;
485-
check_list_invariants(list);
486-
}
487-
488441
/*
489442
* Prepend a new element to the list. A pointer to the modified list
490443
* is returned. Note that this function may or may not destructively

src/backend/optimizer/geqo/geqo_eval.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ merge_clump(PlannerInfo *root, List *clumps, Clump *new_clump, int num_gene,
239239
bool force)
240240
{
241241
ListCell *lc;
242+
int pos;
242243

243244
/* Look for a clump that new_clump can join to */
244245
foreach(lc, clumps)
@@ -304,21 +305,15 @@ merge_clump(PlannerInfo *root, List *clumps, Clump *new_clump, int num_gene,
304305
if (clumps == NIL || new_clump->size == 1)
305306
return lappend(clumps, new_clump);
306307

307-
/* Check if it belongs at the front */
308-
lc = list_head(clumps);
309-
if (new_clump->size > ((Clump *) lfirst(lc))->size)
310-
return lcons(new_clump, clumps);
311-
312308
/* Else search for the place to insert it */
313-
for (;;)
309+
for (pos = 0; pos < list_length(clumps); pos++)
314310
{
315-
ListCell *nxt = lnext(clumps, lc);
311+
Clump *old_clump = (Clump *) list_nth(clumps, pos);
316312

317-
if (nxt == NULL || new_clump->size > ((Clump *) lfirst(nxt))->size)
318-
break; /* it belongs after 'lc', before 'nxt' */
319-
lc = nxt;
313+
if (new_clump->size > old_clump->size)
314+
break; /* new_clump belongs before old_clump */
320315
}
321-
lappend_cell(clumps, lc, new_clump);
316+
clumps = list_insert_nth(clumps, pos, new_clump);
322317

323318
return clumps;
324319
}

src/include/nodes/pg_list.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,10 +514,6 @@ extern List *list_insert_nth(List *list, int pos, void *datum);
514514
extern List *list_insert_nth_int(List *list, int pos, int datum);
515515
extern List *list_insert_nth_oid(List *list, int pos, Oid datum);
516516

517-
extern void lappend_cell(List *list, ListCell *prev, void *datum);
518-
extern void lappend_cell_int(List *list, ListCell *prev, int datum);
519-
extern void lappend_cell_oid(List *list, ListCell *prev, Oid datum);
520-
521517
extern List *lcons(void *datum, List *list);
522518
extern List *lcons_int(int datum, List *list);
523519
extern List *lcons_oid(Oid datum, List *list);

0 commit comments

Comments
 (0)