Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc245776

Browse files
committed
Remove lappend_cell...() family of List functions.
It seems worth getting rid of these functions because they require thecaller 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 pointeras input is list_delete_cell, which nowadays is preferentially usedvia the constrained API foreach_delete_current.)There was only one remaining caller of these functions after commit2f5b8eb, and that was some fairly ugly GEQO code that can be muchmore 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 parent2f5b8eb commitc245776

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
returnlist;
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-
staticListCell*
450-
add_new_cell_after(List*list,ListCell*prev_cell)
451-
{
452-
/* insert_new_cell will assert that this is in-range: */
453-
intpos=prev_cell-list->elements;
454-
455-
returninsert_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,intdatum)
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,Oiddatum)
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
boolforce)
240240
{
241241
ListCell*lc;
242+
intpos;
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
returnlappend(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-
returnlcons(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
returnclumps;
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
externList*list_insert_nth_int(List*list,intpos,intdatum);
515515
externList*list_insert_nth_oid(List*list,intpos,Oiddatum);
516516

517-
externvoidlappend_cell(List*list,ListCell*prev,void*datum);
518-
externvoidlappend_cell_int(List*list,ListCell*prev,intdatum);
519-
externvoidlappend_cell_oid(List*list,ListCell*prev,Oiddatum);
520-
521517
externList*lcons(void*datum,List*list);
522518
externList*lcons_int(intdatum,List*list);
523519
externList*lcons_oid(Oiddatum,List*list);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp