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

Commit64a6059

Browse files
author
Neil Conway
committed
A few minor list-related cleanups:
(1) Replace while loop with the new forboth() construct inparser/analyze.c(2) Replace lcons() with lappend() in SearchCatCacheList(). Since thesenow have the same performance, there is no reason to prefer lcons() inthis case, and using lappend() leads to cleaner code.(3) Improve the name of the second parameter to for_each_cell()
1 parent0ed07d4 commit64a6059

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

‎src/backend/parser/analyze.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2004, 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.311 2004/08/29 05:06:44 momjian Exp $
9+
*$PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.312 2004/09/27 04:12:02 neilc Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -2273,25 +2273,21 @@ getSetColTypes(ParseState *pstate, Node *node)
22732273
staticvoid
22742274
applyColumnNames(List*dst,List*src)
22752275
{
2276-
ListCell*dst_item=list_head(dst);
2277-
ListCell*src_item=list_head(src);
2276+
ListCell*dst_item;
2277+
ListCell*src_item;
22782278

22792279
if (list_length(src)>list_length(dst))
22802280
ereport(ERROR,
22812281
(errcode(ERRCODE_SYNTAX_ERROR),
22822282
errmsg("CREATE TABLE AS specifies too many column names")));
22832283

2284-
while (src_item!=NULL&&dst_item!=NULL)
2284+
forboth(dst_item,dst,src_item,src)
22852285
{
22862286
TargetEntry*d= (TargetEntry*)lfirst(dst_item);
22872287
ColumnDef*s= (ColumnDef*)lfirst(src_item);
22882288

22892289
Assert(d->resdom&& !d->resdom->resjunk);
2290-
22912290
d->resdom->resname=pstrdup(s->colname);
2292-
2293-
dst_item=lnext(dst_item);
2294-
src_item=lnext(src_item);
22952291
}
22962292
}
22972293

‎src/backend/utils/cache/catcache.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/cache/catcache.c,v 1.116 2004/08/29 05:06:50 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/cache/catcache.c,v 1.117 2004/09/27 04:12:02 neilc Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1501,7 +1501,7 @@ SearchCatCacheList(CatCache *cache,
15011501
* worth fixing.
15021502
*/
15031503
ct->refcount++;
1504-
ctlist=lcons(ct,ctlist);
1504+
ctlist=lappend(ctlist,ct);
15051505
nmembers++;
15061506
}
15071507

@@ -1522,16 +1522,17 @@ SearchCatCacheList(CatCache *cache,
15221522

15231523
cl->cl_magic=CL_MAGIC;
15241524
cl->my_cache=cache;
1525-
DLInitElem(&cl->cache_elem,(void*)cl);
1525+
DLInitElem(&cl->cache_elem,cl);
15261526
cl->refcount=0;/* for the moment */
15271527
cl->dead= false;
15281528
cl->ordered=ordered;
15291529
cl->nkeys=nkeys;
15301530
cl->hash_value=lHashValue;
15311531
cl->n_members=nmembers;
1532-
/* The list is backwards because we built it with lcons */
1532+
1533+
Assert(nmembers==list_length(ctlist));
15331534
ctlist_item=list_head(ctlist);
1534-
for (i=nmembers;--i >=0;)
1535+
for (i=0;i<nmembers;i++)
15351536
{
15361537
cl->members[i]=ct= (CatCTup*)lfirst(ctlist_item);
15371538
Assert(ct->c_list==NULL);

‎src/include/nodes/pg_list.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
3131
* Portions Copyright (c) 1994, Regents of the University of California
3232
*
33-
* $PostgreSQL: pgsql/src/include/nodes/pg_list.h,v 1.49 2004/08/29 05:06:57 momjian Exp $
33+
* $PostgreSQL: pgsql/src/include/nodes/pg_list.h,v 1.50 2004/09/27 04:12:03 neilc Exp $
3434
*
3535
*-------------------------------------------------------------------------
3636
*/
@@ -167,8 +167,8 @@ extern intlist_length(List *l);
167167
* a convenience macro which loops through a list starting from a
168168
* specified cell
169169
*/
170-
#definefor_each_cell(cell,l)\
171-
for ((cell) = (l); (cell) != NULL; (cell) = lnext(cell))
170+
#definefor_each_cell(cell,initcell)\
171+
for ((cell) = (initcell); (cell) != NULL; (cell) = lnext(cell))
172172

173173
/*
174174
* forboth -

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp