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

Commit 5d27bf2

Browse files
committed
Make use of new list primitives list_append_unique and list_concat_unique
where applicable.
1 parent ef85f5f commit 5d27bf2

File tree

8 files changed

+44
-65
lines changed

8 files changed

+44
-65
lines changed

src/backend/optimizer/path/joinrels.c

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/path/joinrels.c,v 1.74 2005/06/09 04:18:59 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/path/joinrels.c,v 1.75 2005/07/28 22:27:00 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -44,7 +44,6 @@ make_rels_by_joins(PlannerInfo *root, int level, List **joinrels)
4444
{
4545
List *result_rels = NIL;
4646
List *new_rels;
47-
ListCell *nr;
4847
ListCell *r;
4948
int k;
5049

@@ -121,13 +120,7 @@ make_rels_by_joins(PlannerInfo *root, int level, List **joinrels)
121120
* for subsequent passes, do not enter the same RelOptInfo into
122121
* our output list multiple times.
123122
*/
124-
foreach(nr, new_rels)
125-
{
126-
RelOptInfo *jrel = (RelOptInfo *) lfirst(nr);
127-
128-
if (!list_member_ptr(result_rels, jrel))
129-
result_rels = lcons(jrel, result_rels);
130-
}
123+
result_rels = list_concat_unique_ptr(result_rels, new_rels);
131124
}
132125

133126
/*
@@ -182,8 +175,9 @@ make_rels_by_joins(PlannerInfo *root, int level, List **joinrels)
182175
jrel = make_join_rel(root, old_rel, new_rel,
183176
JOIN_INNER);
184177
/* Avoid making duplicate entries ... */
185-
if (jrel && !list_member_ptr(result_rels, jrel))
186-
result_rels = lcons(jrel, result_rels);
178+
if (jrel)
179+
result_rels = list_append_unique_ptr(result_rels,
180+
jrel);
187181
}
188182
}
189183
}
@@ -224,13 +218,7 @@ make_rels_by_joins(PlannerInfo *root, int level, List **joinrels)
224218
old_rel,
225219
other_rels);
226220

227-
foreach(nr, new_rels)
228-
{
229-
RelOptInfo *jrel = (RelOptInfo *) lfirst(nr);
230-
231-
if (!list_member_ptr(result_rels, jrel))
232-
result_rels = lcons(jrel, result_rels);
233-
}
221+
result_rels = list_concat_unique_ptr(result_rels, new_rels);
234222
}
235223

236224
/*----------

src/backend/optimizer/path/pathkeys.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Portions Copyright (c) 1994, Regents of the University of California
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/optimizer/path/pathkeys.c,v 1.70 2005/07/03 18:26:32 tgl Exp $
14+
* $PostgreSQL: pgsql/src/backend/optimizer/path/pathkeys.c,v 1.71 2005/07/28 22:27:00 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -163,7 +163,7 @@ add_equijoined_keys(PlannerInfo *root, RestrictInfo *restrictinfo)
163163
newset = list_make2(item1, item2);
164164

165165
/* Found a set to merge into our new set */
166-
newset = list_union(newset, curset);
166+
newset = list_concat_unique(newset, curset);
167167

168168
/*
169169
* Remove old set from equi_key_list.
@@ -714,8 +714,7 @@ canonicalize_pathkeys(PlannerInfo *root, List *pathkeys)
714714
* canonicalized the keys, so that equivalent-key knowledge is
715715
* used when deciding if an item is redundant.
716716
*/
717-
if (!list_member_ptr(new_pathkeys, cpathkey))
718-
new_pathkeys = lappend(new_pathkeys, cpathkey);
717+
new_pathkeys = list_append_unique_ptr(new_pathkeys, cpathkey);
719718
}
720719
return new_pathkeys;
721720
}
@@ -1024,8 +1023,7 @@ build_index_pathkeys(PlannerInfo *root,
10241023
* Eliminate redundant ordering info; could happen if query is
10251024
* such that index keys are equijoined...
10261025
*/
1027-
if (!list_member_ptr(retval, cpathkey))
1028-
retval = lappend(retval, cpathkey);
1026+
retval = list_append_unique_ptr(retval, cpathkey);
10291027

10301028
indexkeys++;
10311029
ordering++;
@@ -1467,8 +1465,7 @@ make_pathkeys_for_mergeclauses(PlannerInfo *root,
14671465
* pathkey, a simple ptrMember test is sufficient to detect
14681466
* redundant keys.
14691467
*/
1470-
if (!list_member_ptr(pathkeys, pathkey))
1471-
pathkeys = lappend(pathkeys, pathkey);
1468+
pathkeys = list_append_unique_ptr(pathkeys, pathkey);
14721469
}
14731470

14741471
return pathkeys;

src/backend/optimizer/prep/prepunion.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
*
1616
* IDENTIFICATION
17-
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.124 2005/06/10 02:21:05 tgl Exp $
17+
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.125 2005/07/28 22:27:00 tgl Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -706,21 +706,24 @@ tlist_same_datatypes(List *tlist, List *colTypes, bool junkOK)
706706
List *
707707
find_all_inheritors(Oid parentrel)
708708
{
709-
List *examined_relids = NIL;
710-
List *unexamined_relids = list_make1_oid(parentrel);
709+
List *rels_list;
710+
ListCell *l;
711711

712-
/*
713-
* While the queue of unexamined relids is nonempty, remove the first
714-
* element, mark it examined, and find its direct descendants. NB:
715-
* cannot use foreach(), since we modify the queue inside loop.
712+
/*
713+
* We build a list starting with the given rel and adding all direct and
714+
* indirect children. We can use a single list as both the record of
715+
* already-found rels and the agenda of rels yet to be scanned for more
716+
* children. This is a bit tricky but works because the foreach() macro
717+
* doesn't fetch the next list element until the bottom of the loop.
716718
*/
717-
while (unexamined_relids != NIL)
719+
rels_list = list_make1_oid(parentrel);
720+
721+
foreach(l, rels_list)
718722
{
719-
Oid currentrel = linitial_oid(unexamined_relids);
723+
Oid currentrel = lfirst_oid(l);
720724
List *currentchildren;
721725

722-
unexamined_relids = list_delete_first(unexamined_relids);
723-
examined_relids = lappend_oid(examined_relids, currentrel);
726+
/* Get the direct children of this rel */
724727
currentchildren = find_inheritance_children(currentrel);
725728

726729
/*
@@ -730,11 +733,10 @@ find_all_inheritors(Oid parentrel)
730733
* into an infinite loop, though theoretically there can't be any
731734
* cycles in the inheritance graph anyway.)
732735
*/
733-
currentchildren = list_difference_oid(currentchildren, examined_relids);
734-
unexamined_relids = list_union_oid(unexamined_relids, currentchildren);
736+
rels_list = list_concat_unique_oid(rels_list, currentchildren);
735737
}
736738

737-
return examined_relids;
739+
return rels_list;
738740
}
739741

740742
/*

src/backend/optimizer/util/relnode.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/util/relnode.c,v 1.70 2005/06/09 04:19:00 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/util/relnode.c,v 1.71 2005/07/28 22:27:00 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -619,8 +619,8 @@ subbuild_joinrel_joinlist(RelOptInfo *joinrel,
619619
* in, no great harm is done --- they'll be detected by
620620
* redundant-clause testing when they reach a restriction list.)
621621
*/
622-
if (!list_member_ptr(joinrel->joininfo, rinfo))
623-
joinrel->joininfo = lappend(joinrel->joininfo, rinfo);
622+
joinrel->joininfo = list_append_unique_ptr(joinrel->joininfo,
623+
rinfo);
624624
}
625625
}
626626
}

src/backend/parser/analyze.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.322 2005/06/05 00:38:09 tgl Exp $
9+
* $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.323 2005/07/28 22:27:00 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -2789,8 +2789,8 @@ transformLocking(Query *qry, List *lockedRels, bool forUpdate)
27892789
switch (rte->rtekind)
27902790
{
27912791
case RTE_RELATION:
2792-
if (!list_member_int(rowMarks, i)) /* avoid duplicates */
2793-
rowMarks = lappend_int(rowMarks, i);
2792+
/* use list_append_unique to avoid duplicates */
2793+
rowMarks = list_append_unique_int(rowMarks, i);
27942794
rte->requiredPerms |= ACL_SELECT_FOR_UPDATE;
27952795
break;
27962796
case RTE_SUBQUERY:
@@ -2826,8 +2826,8 @@ transformLocking(Query *qry, List *lockedRels, bool forUpdate)
28262826
switch (rte->rtekind)
28272827
{
28282828
case RTE_RELATION:
2829-
if (!list_member_int(rowMarks, i)) /* avoid duplicates */
2830-
rowMarks = lappend_int(rowMarks, i);
2829+
/* use list_append_unique to avoid duplicates */
2830+
rowMarks = list_append_unique_int(rowMarks, i);
28312831
rte->requiredPerms |= ACL_SELECT_FOR_UPDATE;
28322832
break;
28332833
case RTE_SUBQUERY:

src/backend/rewrite/rewriteHandler.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteHandler.c,v 1.155 2005/06/28 05:08:59 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteHandler.c,v 1.156 2005/07/28 22:27:02 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1001,8 +1001,7 @@ markQueryForLocking(Query *qry, bool forUpdate, bool skipOldNew)
10011001

10021002
if (rte->rtekind == RTE_RELATION)
10031003
{
1004-
if (!list_member_int(qry->rowMarks, rti))
1005-
qry->rowMarks = lappend_int(qry->rowMarks, rti);
1004+
qry->rowMarks = list_append_unique_int(qry->rowMarks, rti);
10061005
rte->requiredPerms |= ACL_SELECT_FOR_UPDATE;
10071006
}
10081007
else if (rte->rtekind == RTE_SUBQUERY)

src/backend/utils/adt/acl.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/acl.c,v 1.122 2005/07/26 16:38:27 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/acl.c,v 1.123 2005/07/28 22:27:02 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2843,8 +2843,7 @@ has_privs_of_role(Oid member, Oid role)
28432843
* graph, we must test for having already seen this role.
28442844
* It is legal for instance to have both A->B and A->C->B.
28452845
*/
2846-
if (!list_member_oid(roles_list, otherid))
2847-
roles_list = lappend_oid(roles_list, otherid);
2846+
roles_list = list_append_unique_oid(roles_list, otherid);
28482847
}
28492848
ReleaseSysCacheList(memlist);
28502849
}
@@ -2931,8 +2930,7 @@ is_member_of_role(Oid member, Oid role)
29312930
* graph, we must test for having already seen this role.
29322931
* It is legal for instance to have both A->B and A->C->B.
29332932
*/
2934-
if (!list_member_oid(roles_list, otherid))
2935-
roles_list = lappend_oid(roles_list, otherid);
2933+
roles_list = list_append_unique_oid(roles_list, otherid);
29362934
}
29372935
ReleaseSysCacheList(memlist);
29382936
}
@@ -3024,8 +3022,7 @@ is_admin_of_role(Oid member, Oid role)
30243022
break;
30253023
}
30263024

3027-
if (!list_member_oid(roles_list, otherid))
3028-
roles_list = lappend_oid(roles_list, otherid);
3025+
roles_list = list_append_unique_oid(roles_list, otherid);
30293026
}
30303027
ReleaseSysCacheList(memlist);
30313028
if (result)

src/backend/utils/init/flatfiles.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
2424
* Portions Copyright (c) 1994, Regents of the University of California
2525
*
26-
* $PostgreSQL: pgsql/src/backend/utils/init/flatfiles.c,v 1.12 2005/07/04 04:51:50 tgl Exp $
26+
* $PostgreSQL: pgsql/src/backend/utils/init/flatfiles.c,v 1.13 2005/07/28 22:27:02 tgl Exp $
2727
*
2828
*-------------------------------------------------------------------------
2929
*/
@@ -571,12 +571,8 @@ write_auth_file(Relation rel_authid, Relation rel_authmem)
571571
* Now add all the new roles to roles_list.
572572
*/
573573
for (i = first_found; i <= last_found; i++)
574-
{
575-
Oid rolid = authmem_info[i].roleid;
576-
577-
if (!list_member_oid(roles_list, rolid))
578-
roles_list = lappend_oid(roles_list, rolid);
579-
}
574+
roles_list = list_append_unique_oid(roles_list,
575+
authmem_info[i].roleid);
580576
}
581577

582578
/*

0 commit comments

Comments
 (0)