Commit 5d27bf20 authored by Tom Lane's avatar Tom Lane

Make use of new list primitives list_append_unique and list_concat_unique

where applicable.
parent ef85f5fa
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/path/joinrels.c,v 1.74 2005/06/09 04:18:59 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/path/joinrels.c,v 1.75 2005/07/28 22:27:00 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -44,7 +44,6 @@ make_rels_by_joins(PlannerInfo *root, int level, List **joinrels) ...@@ -44,7 +44,6 @@ make_rels_by_joins(PlannerInfo *root, int level, List **joinrels)
{ {
List *result_rels = NIL; List *result_rels = NIL;
List *new_rels; List *new_rels;
ListCell *nr;
ListCell *r; ListCell *r;
int k; int k;
...@@ -121,13 +120,7 @@ make_rels_by_joins(PlannerInfo *root, int level, List **joinrels) ...@@ -121,13 +120,7 @@ make_rels_by_joins(PlannerInfo *root, int level, List **joinrels)
* for subsequent passes, do not enter the same RelOptInfo into * for subsequent passes, do not enter the same RelOptInfo into
* our output list multiple times. * our output list multiple times.
*/ */
foreach(nr, new_rels) result_rels = list_concat_unique_ptr(result_rels, new_rels);
{
RelOptInfo *jrel = (RelOptInfo *) lfirst(nr);
if (!list_member_ptr(result_rels, jrel))
result_rels = lcons(jrel, result_rels);
}
} }
/* /*
...@@ -182,8 +175,9 @@ make_rels_by_joins(PlannerInfo *root, int level, List **joinrels) ...@@ -182,8 +175,9 @@ make_rels_by_joins(PlannerInfo *root, int level, List **joinrels)
jrel = make_join_rel(root, old_rel, new_rel, jrel = make_join_rel(root, old_rel, new_rel,
JOIN_INNER); JOIN_INNER);
/* Avoid making duplicate entries ... */ /* Avoid making duplicate entries ... */
if (jrel && !list_member_ptr(result_rels, jrel)) if (jrel)
result_rels = lcons(jrel, result_rels); result_rels = list_append_unique_ptr(result_rels,
jrel);
} }
} }
} }
...@@ -224,13 +218,7 @@ make_rels_by_joins(PlannerInfo *root, int level, List **joinrels) ...@@ -224,13 +218,7 @@ make_rels_by_joins(PlannerInfo *root, int level, List **joinrels)
old_rel, old_rel,
other_rels); other_rels);
foreach(nr, new_rels) result_rels = list_concat_unique_ptr(result_rels, new_rels);
{
RelOptInfo *jrel = (RelOptInfo *) lfirst(nr);
if (!list_member_ptr(result_rels, jrel))
result_rels = lcons(jrel, result_rels);
}
} }
/*---------- /*----------
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/path/pathkeys.c,v 1.70 2005/07/03 18:26:32 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/path/pathkeys.c,v 1.71 2005/07/28 22:27:00 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -163,7 +163,7 @@ add_equijoined_keys(PlannerInfo *root, RestrictInfo *restrictinfo) ...@@ -163,7 +163,7 @@ add_equijoined_keys(PlannerInfo *root, RestrictInfo *restrictinfo)
newset = list_make2(item1, item2); newset = list_make2(item1, item2);
/* Found a set to merge into our new set */ /* Found a set to merge into our new set */
newset = list_union(newset, curset); newset = list_concat_unique(newset, curset);
/* /*
* Remove old set from equi_key_list. * Remove old set from equi_key_list.
...@@ -714,8 +714,7 @@ canonicalize_pathkeys(PlannerInfo *root, List *pathkeys) ...@@ -714,8 +714,7 @@ canonicalize_pathkeys(PlannerInfo *root, List *pathkeys)
* canonicalized the keys, so that equivalent-key knowledge is * canonicalized the keys, so that equivalent-key knowledge is
* used when deciding if an item is redundant. * used when deciding if an item is redundant.
*/ */
if (!list_member_ptr(new_pathkeys, cpathkey)) new_pathkeys = list_append_unique_ptr(new_pathkeys, cpathkey);
new_pathkeys = lappend(new_pathkeys, cpathkey);
} }
return new_pathkeys; return new_pathkeys;
} }
...@@ -1024,8 +1023,7 @@ build_index_pathkeys(PlannerInfo *root, ...@@ -1024,8 +1023,7 @@ build_index_pathkeys(PlannerInfo *root,
* Eliminate redundant ordering info; could happen if query is * Eliminate redundant ordering info; could happen if query is
* such that index keys are equijoined... * such that index keys are equijoined...
*/ */
if (!list_member_ptr(retval, cpathkey)) retval = list_append_unique_ptr(retval, cpathkey);
retval = lappend(retval, cpathkey);
indexkeys++; indexkeys++;
ordering++; ordering++;
...@@ -1467,8 +1465,7 @@ make_pathkeys_for_mergeclauses(PlannerInfo *root, ...@@ -1467,8 +1465,7 @@ make_pathkeys_for_mergeclauses(PlannerInfo *root,
* pathkey, a simple ptrMember test is sufficient to detect * pathkey, a simple ptrMember test is sufficient to detect
* redundant keys. * redundant keys.
*/ */
if (!list_member_ptr(pathkeys, pathkey)) pathkeys = list_append_unique_ptr(pathkeys, pathkey);
pathkeys = lappend(pathkeys, pathkey);
} }
return pathkeys; return pathkeys;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.124 2005/06/10 02:21:05 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.125 2005/07/28 22:27:00 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -706,21 +706,24 @@ tlist_same_datatypes(List *tlist, List *colTypes, bool junkOK) ...@@ -706,21 +706,24 @@ tlist_same_datatypes(List *tlist, List *colTypes, bool junkOK)
List * List *
find_all_inheritors(Oid parentrel) find_all_inheritors(Oid parentrel)
{ {
List *examined_relids = NIL; List *rels_list;
List *unexamined_relids = list_make1_oid(parentrel); ListCell *l;
/* /*
* While the queue of unexamined relids is nonempty, remove the first * We build a list starting with the given rel and adding all direct and
* element, mark it examined, and find its direct descendants. NB: * indirect children. We can use a single list as both the record of
* cannot use foreach(), since we modify the queue inside loop. * already-found rels and the agenda of rels yet to be scanned for more
* children. This is a bit tricky but works because the foreach() macro
* doesn't fetch the next list element until the bottom of the loop.
*/ */
while (unexamined_relids != NIL) rels_list = list_make1_oid(parentrel);
foreach(l, rels_list)
{ {
Oid currentrel = linitial_oid(unexamined_relids); Oid currentrel = lfirst_oid(l);
List *currentchildren; List *currentchildren;
unexamined_relids = list_delete_first(unexamined_relids); /* Get the direct children of this rel */
examined_relids = lappend_oid(examined_relids, currentrel);
currentchildren = find_inheritance_children(currentrel); currentchildren = find_inheritance_children(currentrel);
/* /*
...@@ -730,11 +733,10 @@ find_all_inheritors(Oid parentrel) ...@@ -730,11 +733,10 @@ find_all_inheritors(Oid parentrel)
* into an infinite loop, though theoretically there can't be any * into an infinite loop, though theoretically there can't be any
* cycles in the inheritance graph anyway.) * cycles in the inheritance graph anyway.)
*/ */
currentchildren = list_difference_oid(currentchildren, examined_relids); rels_list = list_concat_unique_oid(rels_list, currentchildren);
unexamined_relids = list_union_oid(unexamined_relids, currentchildren);
} }
return examined_relids; return rels_list;
} }
/* /*
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/util/relnode.c,v 1.70 2005/06/09 04:19:00 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/util/relnode.c,v 1.71 2005/07/28 22:27:00 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -619,8 +619,8 @@ subbuild_joinrel_joinlist(RelOptInfo *joinrel, ...@@ -619,8 +619,8 @@ subbuild_joinrel_joinlist(RelOptInfo *joinrel,
* in, no great harm is done --- they'll be detected by * in, no great harm is done --- they'll be detected by
* redundant-clause testing when they reach a restriction list.) * redundant-clause testing when they reach a restriction list.)
*/ */
if (!list_member_ptr(joinrel->joininfo, rinfo)) joinrel->joininfo = list_append_unique_ptr(joinrel->joininfo,
joinrel->joininfo = lappend(joinrel->joininfo, rinfo); rinfo);
} }
} }
} }
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.322 2005/06/05 00:38:09 tgl Exp $ * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.323 2005/07/28 22:27:00 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -2789,8 +2789,8 @@ transformLocking(Query *qry, List *lockedRels, bool forUpdate) ...@@ -2789,8 +2789,8 @@ transformLocking(Query *qry, List *lockedRels, bool forUpdate)
switch (rte->rtekind) switch (rte->rtekind)
{ {
case RTE_RELATION: case RTE_RELATION:
if (!list_member_int(rowMarks, i)) /* avoid duplicates */ /* use list_append_unique to avoid duplicates */
rowMarks = lappend_int(rowMarks, i); rowMarks = list_append_unique_int(rowMarks, i);
rte->requiredPerms |= ACL_SELECT_FOR_UPDATE; rte->requiredPerms |= ACL_SELECT_FOR_UPDATE;
break; break;
case RTE_SUBQUERY: case RTE_SUBQUERY:
...@@ -2826,8 +2826,8 @@ transformLocking(Query *qry, List *lockedRels, bool forUpdate) ...@@ -2826,8 +2826,8 @@ transformLocking(Query *qry, List *lockedRels, bool forUpdate)
switch (rte->rtekind) switch (rte->rtekind)
{ {
case RTE_RELATION: case RTE_RELATION:
if (!list_member_int(rowMarks, i)) /* avoid duplicates */ /* use list_append_unique to avoid duplicates */
rowMarks = lappend_int(rowMarks, i); rowMarks = list_append_unique_int(rowMarks, i);
rte->requiredPerms |= ACL_SELECT_FOR_UPDATE; rte->requiredPerms |= ACL_SELECT_FOR_UPDATE;
break; break;
case RTE_SUBQUERY: case RTE_SUBQUERY:
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteHandler.c,v 1.155 2005/06/28 05:08:59 tgl Exp $ * $PostgreSQL: pgsql/src/backend/rewrite/rewriteHandler.c,v 1.156 2005/07/28 22:27:02 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1001,8 +1001,7 @@ markQueryForLocking(Query *qry, bool forUpdate, bool skipOldNew) ...@@ -1001,8 +1001,7 @@ markQueryForLocking(Query *qry, bool forUpdate, bool skipOldNew)
if (rte->rtekind == RTE_RELATION) if (rte->rtekind == RTE_RELATION)
{ {
if (!list_member_int(qry->rowMarks, rti)) qry->rowMarks = list_append_unique_int(qry->rowMarks, rti);
qry->rowMarks = lappend_int(qry->rowMarks, rti);
rte->requiredPerms |= ACL_SELECT_FOR_UPDATE; rte->requiredPerms |= ACL_SELECT_FOR_UPDATE;
} }
else if (rte->rtekind == RTE_SUBQUERY) else if (rte->rtekind == RTE_SUBQUERY)
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/acl.c,v 1.122 2005/07/26 16:38:27 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/acl.c,v 1.123 2005/07/28 22:27:02 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -2843,8 +2843,7 @@ has_privs_of_role(Oid member, Oid role) ...@@ -2843,8 +2843,7 @@ has_privs_of_role(Oid member, Oid role)
* graph, we must test for having already seen this role. * graph, we must test for having already seen this role.
* It is legal for instance to have both A->B and A->C->B. * It is legal for instance to have both A->B and A->C->B.
*/ */
if (!list_member_oid(roles_list, otherid)) roles_list = list_append_unique_oid(roles_list, otherid);
roles_list = lappend_oid(roles_list, otherid);
} }
ReleaseSysCacheList(memlist); ReleaseSysCacheList(memlist);
} }
...@@ -2931,8 +2930,7 @@ is_member_of_role(Oid member, Oid role) ...@@ -2931,8 +2930,7 @@ is_member_of_role(Oid member, Oid role)
* graph, we must test for having already seen this role. * graph, we must test for having already seen this role.
* It is legal for instance to have both A->B and A->C->B. * It is legal for instance to have both A->B and A->C->B.
*/ */
if (!list_member_oid(roles_list, otherid)) roles_list = list_append_unique_oid(roles_list, otherid);
roles_list = lappend_oid(roles_list, otherid);
} }
ReleaseSysCacheList(memlist); ReleaseSysCacheList(memlist);
} }
...@@ -3024,8 +3022,7 @@ is_admin_of_role(Oid member, Oid role) ...@@ -3024,8 +3022,7 @@ is_admin_of_role(Oid member, Oid role)
break; break;
} }
if (!list_member_oid(roles_list, otherid)) roles_list = list_append_unique_oid(roles_list, otherid);
roles_list = lappend_oid(roles_list, otherid);
} }
ReleaseSysCacheList(memlist); ReleaseSysCacheList(memlist);
if (result) if (result)
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/backend/utils/init/flatfiles.c,v 1.12 2005/07/04 04:51:50 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/init/flatfiles.c,v 1.13 2005/07/28 22:27:02 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -571,12 +571,8 @@ write_auth_file(Relation rel_authid, Relation rel_authmem) ...@@ -571,12 +571,8 @@ write_auth_file(Relation rel_authid, Relation rel_authmem)
* Now add all the new roles to roles_list. * Now add all the new roles to roles_list.
*/ */
for (i = first_found; i <= last_found; i++) for (i = first_found; i <= last_found; i++)
{ roles_list = list_append_unique_oid(roles_list,
Oid rolid = authmem_info[i].roleid; authmem_info[i].roleid);
if (!list_member_oid(roles_list, rolid))
roles_list = lappend_oid(roles_list, rolid);
}
} }
/* /*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment